Header file
#include <algorithm>
function implementation
template<classclass t>const t& val) { while ( First!= last) { ifreturn first ; + + first; } return Last ;}
Example 1 (vector)
#include <iostream>#include<algorithm>#include<vector>using namespacestd;intmain () {vector<string>m; M.push_back ("Hello"); M.push_back ("Hello2"); M.push_back ("Hello3"); if(Find (M.begin (), M.end (),"Hello") ==m.end ()) cout<<"No"<<Endl; Elsecout<<"Yes"<<Endl;}
Example 2 (SET)
#include <iostream>#include<algorithm>#include<string>#include<Set>using namespacestd;intMain () {Set<string>m; M.insert ("Hello"); M.insert ("Hello2"); M.insert ("Hello3"); if(Find (M.begin (), M.end (),"Hello") ==m.end ()) cout<<"No"<<Endl; Elsecout<<"Yes"<<Endl;}
Note 1:set itself has a find function, for example:
#include <iostream>#include<algorithm>#include<string>#include<Set>using namespacestd;intMain () {Set<string>m; M.insert ("Hello"); M.insert ("Hello2"); M.insert ("Hello3"); if(Find (M.begin (), M.end (),"Hello") ==m.end ()) cout<<"No"<<Endl; Elsecout<<"Yes"<<Endl;}
Note 2:string itself has a find function, for example:
#include <iostream>#include<algorithm>#include<string>using namespacestd;intMain () {strings ="Helllo"; if(S.find ("e") ==string:: NPOs) //yes cout<<"No"<<Endl; Elsecout<<"Yes"<<Endl; if(S.find ("Z") ==string:: NPOs) //no cout<<"No"<<Endl; Elsecout<<"Yes"<<Endl;}
C++find function Usage