zoukankan      html  css  js  c++  java
  • C++ STL中允许重复key的multimap

    在实际的项目中可能会碰到key重复的情况,正常的MAP类型是不允许重复的key,所以就要使用multimap了,multimap的使用和map基本类似,可以无缝对接

    #include <map>

    typedef pair<string, int> PAIR;

    ostream& operator<<(ostream& out, const PAIR& p) {
    return out << p.first << " " << p.second;
    }

    multimap<string, int> name_score_map;


    //name_score_map["LiMin"] = 90;  //主要插入的方式和map有所区别
    name_score_map.insert(make_pair("LiMin", 90));
    //name_score_map["LiMin"] = 91;
    name_score_map.insert(make_pair("LiMin", 91));
    //name_score_map["ZiLinMi"] = 79;
    name_score_map.insert(make_pair("ZiLinMi", 79));
    //name_score_map["BoB"] = 92;
    name_score_map.insert(make_pair("BoB", 92));
    name_score_map.insert(make_pair("Bing", 99));

    for (multimap<string, int>::iterator iter = name_score_map.begin(); iter != name_score_map.end(); ++iter) {
    cout << *iter << endl;
    //cout << iter->first << " => " << iter->second << ' ';
    }

  • 相关阅读:
    git客户端
    Autowired注解的妙用---在Controller里的构造函数里获取需要注入的对象
    面向对象的理解
    改变对update的做法
    时间戳与日期相互转换
    Git随记
    json数据传输有感
    Mybatis的批量CRUD
    并发与线程有感
    dpkg --info
  • 原文地址:https://www.cnblogs.com/hushaojun/p/6014221.html
Copyright © 2011-2022 走看看