We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 95a3729 commit 07f4c2eCopy full SHA for 07f4c2e
cpp_11/003_stl_std_unordered_map.cpp
@@ -1 +1,28 @@
1
-1
+#include <iostream>
2
+#include <string>
3
+#include <unordered_map>
4
+
5
+int main()
6
+{
7
+ // 创建三个 string 的 unordered_map (映射到 string )
8
+ std::unordered_map<std::string, std::string> u = {
9
+ {"RED","#FF0000"},
10
+ {"GREEN","#00FF00"},
11
+ {"BLUE","#0000FF"}
12
+ };
13
14
+ // 迭代并打印 unordered_map 的关键和值
15
+ for( const auto& n : u ) {
16
+ std::cout << "Key:[" << n.first << "] Value:[" << n.second << "]\n";
17
+ }
18
19
+ // 添加新入口到 unordered_map
20
+ u["BLACK"] = "#000000";
21
+ u["WHITE"] = "#FFFFFF";
22
23
+ // 用关键输出值
24
+ std::cout << "The HEX of color RED is:[" << u["RED"] << "]\n";
25
+ std::cout << "The HEX of color BLACK is:[" << u["BLACK"] << "]\n";
26
27
+ return 0;
28
+}
0 commit comments