#include <iostream>     // cout
#include <algorithm>    // find
#include <vector>       // vector
#include <typeinfo>

using namespace std;
int main () {
    // using find with array and pointer:
    int myints[] = { 10, 20, 30, 40 };
    int * p;
    
    p = find (myints, myints+4, 30);  //返回查找到的元素的物理地址
    cout<<p<<"\n";
    if (p != myints+4)
        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+4);
    vector<int>::iterator it;
    
    it = find (myvector.begin(), myvector.end(), 30);
    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 0;
}

 

转载于:https://www.cnblogs.com/sea-stream/p/9817204.html

Logo

魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。

更多推荐