zoukankan      html  css  js  c++  java
  • map按value查找相应元素

    find_if算法用来在map中查找value符合条件的pair元素,返回指向该符合条件元素的迭代器,如果找到,那么返回最后一个元素的后一个元素end();

    1.首先要定义头文件
     #include <algorithm>

    2.定义一个比较函数

    class map_finder
    {
    public:
        map_finder(const std::wstring &cmp_wstring) :m_s_cmp_string(cmp_wstring){}
        bool operator ()(const std::map<int, std::wstring>::value_type &pair)
        {
                return pair.second == m_s_cmp_string;
        }
    private:
            const std::wstring &m_s_cmp_string;
    };

    3.查找

     map<int, wstring>::iterator it = m_listCtrl.m_secLineText.end();
           wstring s = str.GetString();
           it = std::find_if(m_listCtrl.m_secLineText.begin(), m_listCtrl.m_secLineText.end(), map_finder(s));
             if (it != m_listCtrl.m_secLineText.end())
            {
                int a = it->first;
                cout << " find!!!! " << endl;
            }
            else
            {
                cout << "Not find!!!! " << endl;
            }

    赌上我的人生为梦想,即使是臭名远扬,也要我的名字响彻天堂
  • 相关阅读:
    通过elasticsearch对日志进行搜索热词统计
    登陆获取shell时的配置文件加载过程
    linux共享库加载
    linux安全相关
    ELK常用API使用方法
    linux bash缓存
    redis主从架构及redis集群
    排查电脑的网络问题
    Logstash添加Protobuf解析插件
    Macaca上手体验
  • 原文地址:https://www.cnblogs.com/ye-ming/p/7114794.html
Copyright © 2011-2022 走看看