码迷,mamicode.com
首页 > 编程语言 > 详细

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

时间:2018-06-29 12:09:02      阅读:180      评论:0      收藏:0      [点我收藏+]

标签:const   c++   div   ***   first   air   style   class   ons   

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

 

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

标签:const   c++   div   ***   first   air   style   class   ons   

原文地址:https://www.cnblogs.com/kilen/p/9242581.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!