19.允许重复的unordered_map

 1 #include <string>
 2 #include <iostream>
 3 //查询性能最高
 4 //允许重复的,hash_map
 5 #include <unordered_map>
 6 #include <algorithm>
 7 using namespace std;
 8 
 9 
10 void main()
11 {
12     //允许重复的映射
13     unordered_multimap<string, double>mymap{ {"a1",113},{ "a2",143 },{ "a3",1123 } };
14 
15     mymap.insert(pair<string, double>("a4", 345));
16     mymap.insert(pair<string, double>("a4", 315));
17     mymap.insert(pair<string, double>("a4", 325));
18     mymap.insert(pair<string, double>("a4", 335));
19 
20     /*mymap.insert(unordered_multimap<string, double>::value_type("a5", 3425));*/
21 
22     /*for (auto i : mymap)
23     {
24         cout << i.first << "  " << i.second << endl;
25     }*/
26 
27     /*auto it = mymap.find("a1");
28     if (it != mymap.end())
29     {
30         cout << it->second << endl;
31     }*/
32 
33     //查找所有
34     auto it = mymap.equal_range("a4");
35 
36     for_each(it.first, it.second, [](unordered_multimap<string, double>::value_type &x) {cout << x.first << "  " << x.second << endl; });
37     cin.get();
38 }
原文地址:https://www.cnblogs.com/xiaochi/p/8629668.html