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

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM