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

 

相关文章:

  • 2022-12-23
  • 2021-11-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-25
猜你喜欢
  • 2021-09-21
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-08-17
  • 2021-07-11
  • 2021-05-18
相关资源
相似解决方案