find用法

 1 // find example
 2 #include <iostream>     // std::cout
 3 #include <algorithm>    // std::find
 4 #include <vector>       // std::vector
 5 
 6 int main () {
 7   // using std::find with array and pointer:
 8   int myints[] = { 10, 20, 30, 40 };
 9   int * p;
10 
11   p = std::find (myints, myints+4, 30);
12   if (p != myints+4)
13     std::cout << "Element found in myints: " << *p << '\n';
14   else
15     std::cout << "Element not found in myints\n";
16 
17   // using std::find with vector and iterator:
18   std::vector<int> myvector (myints,myints+4);
19   std::vector<int>::iterator it;
20 
21   it = find (myvector.begin(), myvector.end(), 30);
22   if (it != myvector.end())
23     std::cout << "Element found in myvector: " << *it << '\n';
24   else
25     std::cout << "Element not found in myvector\n";
26 
27   return 0;
28 }

 

posted @ 2019-06-05 16:08  敲代码不BB  阅读(167)  评论(0编辑  收藏  举报