#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;
}
转载于:https://my.oschina.net/u/923087/blog/279097