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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值