1 #include <string> 2 //老版本的unordered_map(已经废弃不再使用) 3 #include <hash_map> 4 #include <iostream> 5 using namespace std; 6 7 8 void main() 9 { 10 //允许重复的映射 11 hash_map<string, double>mymap{ { "a1",113 },{ "a2",143 },{ "a3",1123 } }; 12 13 mymap.insert(pair<string, double>("a4", 345)); 14 mymap.insert(pair<string, double>("a4", 315)); 15 mymap.insert(pair<string, double>("a4", 325)); 16 mymap.insert(pair<string, double>("a4", 335)); 17 18 19 20 for (auto i : mymap) 21 { 22 cout << i.first << " " << i.second << endl; 23 } 24 25 cin.get(); 26 }