The Find function primarily implements finding the specified element within the container, and the element must be of the basic data type.
The lookup succeeded in returning an iterator to the specified element, and the lookup failed to return an end iterator.
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>UsingNamespaceStdIntMain () {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; else cout << yes "<< Endl;}
Example 2 (SET)
#include <iostream>#include <algorithm>#include <String>#include <Set>UsingNamespaceStdIntMain () {set<String>M M.insert ("Hello"); M.insert ("hello2); M.insert ( "hello3" Span style= "color: #000000;" >); if (Find (M.begin (), M.end (), hello M.end ()) cout << no" < < Endl; else cout << yes "<< Endl;}
Note 1:set itself has a find function, for example:
#include <iostream>#include <algorithm>#include <String>#include <Set>UsingNamespaceStdIntMain () {set<String>M M.insert ("Hello"); M.insert ("hello2); M.insert ( "hello3" Span style= "color: #000000;" >); if (Find (M.begin (), M.end (), hello M.end ()) cout << no" < < Endl; else cout << yes "<< Endl;}
Note 2:string itself has a find function, for example:
#include <iostream>#include <algorithm>#include <String>UsingNamespaceStdIntMain () {string s ="Helllo";if (S.find ("E") ==String:: NPOs)Yes cout <<"No"<<EndlElsecout << "Yes" << Endl; if (S.find ("z") = = string:: NPOs) //no cout << "no" << Endl else cout << "Yes" << Endl;}
The use of the Find function in C + +