c++ primer习题9.13
2013-08-22 16:25
232 查看
#include <iostream> #include <vector> #include <list> using namespace std; template<typename T1, typename T2> T1 findInt(T1 beg, T1 end, T2 ival) { while(beg!=end) { if(*beg==ival) break; else ++beg; } return beg; } int main() { int ia[]={0,1,2,3,4,5,6,7,8}; vector<int> ivec(ia, ia+9); cout<<"Enter a integer:"<<endl; int ival; cin>>ival; vector<int>::iterator it; it=findInt(ivec.begin(), ivec.end(), ival); if(it!=ivec.end()) cout<<ival<<" is a element of the vector."<<endl; else cout<<ival<<" is not a element of the vector."<<endl; return 0; }
相关文章推荐
- c++ primer习题9.13
- 《c++ Primer(第四版)》习题9.13
- C++ Primer 中文版 第4版 习题9.13
- C++ primer 习题练习:9.13
- C++ Primer 习题 5.18 vector中存放指针
- c++ primer第五版(中文)习题答案 第十章第一节第一小节-概述
- c++ primer 第四章习题(1)
- c++ primer第五版(中文)习题答案 第十章第三节第三小节-lambda捕获和返回
- c++ primer第五版(中文)习题答案 第十章第四节第一小节-插入迭代器
- 《C++ Primer》第五版课后习题解答_第六章(3)(16-26)
- C++ primer 习题8.3
- c++ primer(第五版)学习笔记及习题答案代码版(第十二章)动态内存与智能指针
- 《c++ Primer(第四版)》习题 9.34
- c++ primer习题9.42, 10.5
- c++ primer 习题 14.37
- C++ Primer 5th 课后习题8.10、8.11、8.13
- C++ Primer一道习题, 类的继承
- c++ primer习题9.26答案错误
- C++ Primer 第10章 习题 10.18
- C++ Primer 第10章 习题10.25