zoukankan      html  css  js  c++  java
  • 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[] = { 10, 20, 30, 40 };
        int * p;
        
        p = find (myints, myints+4, 30);  //返回查找到的元素的物理地址
        cout<<p<<"
    ";
        if (p != myints+4)
            cout << "Element found in myints: " << *p << '
    ';
        else
            cout << "Element not found in myints
    ";
        
        // 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()<<"
    ";
        if (it != myvector.end())
            cout << "Element found in myvector: " << *it << '
    ';
        else
            cout << "Element not found in myvector
    ";
        
        return 0;
    }

  • 相关阅读:
    数据库部署
    css常见问题
    extjs记录
    C#相关问题
    window疑难问题解决
    常用linq
    不同数据库之间的相互链接
    聊天数据库
    无线路由接入
    [转]如何才能让你的简历被谷歌相中
  • 原文地址:https://www.cnblogs.com/sea-stream/p/9817204.html
Copyright © 2011-2022 走看看