迭代器2

来源:互联网 发布:左飞 算法之美pdf 编辑:程序博客网 时间:2024/05/19 18:42
#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;elsecout << "找到了" << 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;}

0 0
原创粉丝点击