#include <iostream>
#include <vector>
#include <string>
using namespace std;
vector<int>::iterator findInt(vector<int>::iterator beg, vector<int>::iterator end, int ival)
{
while (beg != end)
if (*beg == ival)
break;
else
++beg;
return beg;
}
int main()
{
int a[] = { 0, 1, 2, 3, 4, 5 };
vector<int> ivec(a, a + 6);//(a, a + 6)这两个都是迭代器,
vector<int>::iterator 结果 = findInt(ivec.begin(), ivec.end(), 3);
if (结果 == ivec.end())
cout << "没有找到" << endl;
else
cout << "找到了" << endl;
/*vector<string> svec;
string str;
cout << "Enter some string(Ctrl+Z to end):" << endl;
while(cin >> str);
{
svec.push_back(str);
}
for (vector<string>::iterator iter = svec.begin(); iter != svec.end(); ++iter)
{
cout << *iter << endl;
}*/
return 0;
}
迭代器2
最新推荐文章于 2024-02-29 14:09:02 发布