1 C++ map.insert: pair 和 make_pair 区别
- 2 \********************************* 3 map<uint32_t, string> temp;
- 4 1. temp[1] = "template";
- 5 2.temp.insert(pair<uint32_t, string>(1, "template"));
- 6 3.temp.insert(make_pair(1, "template"));
- 7
8 pair 实质上是一个结构体, 其主要的两个成员变量是 first 和 second, 因此有了
- for(const auto& i : temp) {
- 9 cout << "first =" << i.first; // i 也就是一个 pair;
- 10 cout << "second =" << i.second;
- 11 }
12 pair 需要指定构造的类型, make_pair 可以隐式转换, 即将 1 转成 uint32_t, template 转成 string 类型.
13 \*********************************\
来源: http://www.bubuko.com/infodetail-2663692.html