C++ map.insert: pair和make_pair区别

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

猜你喜欢

转载自www.cnblogs.com/kilen/p/9242581.html