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 *********************************