STL find_if demo

来源:互联网 发布:矩阵式管理 编辑:程序博客网 时间:2024/05/12 20:39
#include <iostream>#include <vector>#include <algorithm>#include <string>using namespace std;bool GT3(string s);int main(){vector<string> svec;string word;while (cin >> word) {svec.push_back(word);}vector<string>::iterator it = find_if(svec.begin(),svec.end(), GT3);if (it == svec.end()) {cout << "not found." << endl;} else {cout << "found at index " << it-svec.begin() << endl;}getchar();return 0;}bool GT3(string s) {return s.size() > 3;}

0 0
原创粉丝点击