c++ 查找数组或者容器元素是否存在(find)

#include <iostream>     // cout
#include <algorithm> // find
#include <vector> // vector
#include <typeinfo> using namespace std;
int main () {
// using find with array and pointer:
int myints[] = { , , , };
int * p; p = find (myints, myints+, ); //返回查找到的元素的物理地址
cout<<p<<"\n";
if (p != myints+)
cout << "Element found in myints: " << *p << '\n';
else
cout << "Element not found in myints\n"; // using find with vector and iterator:
vector<int> myvector (myints,myints+);
vector<int>::iterator it; it = find (myvector.begin(), myvector.end(), );
cout<<typeid(it).name()<<"\n";
if (it != myvector.end())
cout << "Element found in myvector: " << *it << '\n';
else
cout << "Element not found in myvector\n"; return ;
}
上一篇:Jenkins+PowerShell持续集成环境搭建(五)SSRS项目


下一篇:实现外卖选餐时两级 tableView 联动效果