zoukankan      html  css  js  c++  java
  • C++ Multimap运用实例—查找元素

    C++ Multimap运用实例—查找元素

    #include <map>
    #include <iostream>
    #include <algorithm>
    #include <utility>
    
    using namespace std;
    
    int main()
    {
        map<float, float> map1 = { {1,7},{2,8},{3,9},{4,8},{5,6},{6,1},{7,3} };
        
        auto posKey = map1.find(3.0);
        if (posKey != map1.end())
        {
            cout << "" << posKey->first << "  " << posKey->second << endl;
        }
    
        auto posVal = find_if(map1.begin(),map1.end(),
            [](const pair<float, float>& elem1) {
                return elem1.second == 3.0;
            });
    
        if (posVal != map1.end())
        {
            cout << posVal->first << "   " << posVal->second << "" << endl;
        }
    
    
        system("pause");
        return 0;
    }

    3 9
    7 3
    请按任意键继续. . .

    代码参考:C++标准库(第2版)

  • 相关阅读:
    列表、元组、字符串的相互转化
    python中的常用BIF
    python中的类型
    python内置模块
    打印字体颜色整理
    xml操作
    内置函数
    迭代器
    装饰器
    函数
  • 原文地址:https://www.cnblogs.com/herd/p/12069894.html
Copyright © 2011-2022 走看看