STL中常见find()函数的使用---std::find ,set.find, multiset.find, map.find和multimap.find

1.通用std::find 函数

例子1:

1 // find example 2 #include <iostream> 3 #include <algorithm> 4 #include <vector> 5 usingnamespacestd; 6 7 intmain () { 8 intmyints[] = { 10, 20, 30 ,40 }; 9 int* p; 10 11 // pointer to array element: 12 p = find(myints,myints+4,30); 13 ++p; 14 cout << "The element following 30 is " << *p << endl; 15 16 vector<int> myvector (myints,myints+4); 17 vector<int>::iterator it; 18 19 // iterator to vector element: 20 it = find (myvector.begin(), myvector.end(), 30); 21 ++it; 22 cout << "The element following 30 is " << *it << endl; 23 24 return0; 25 }

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/zwwgjp.html