MCPcopy Create free account
hub / github.com/changkun/modern-cpp-tutorial / main

Function main

code/4/4.2.cpp:14–36  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

12#include <map>
13
14int main() {
15 // 两组结构按同样的顺序初始化
16 std::unordered_map<int, std::string> u = {
17 {1, "1"},
18 {3, "3"},
19 {2, "2"}
20 };
21 std::map<int, std::string> v = {
22 {1, "1"},
23 {3, "3"},
24 {2, "2"}
25 };
26
27 // 分别对两组结构进行遍历
28 std::cout << "std::unordered_map" << std::endl;
29 for( const auto & n : u)
30 std::cout << "Key:[" << n.first << "] Value:[" << n.second << "]\n";
31
32 std::cout << std::endl;
33 std::cout << "std::map" << std::endl;
34 for( const auto & n : v)
35 std::cout << "Key:[" << n.first << "] Value:[" << n.second << "]\n";
36}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected