zoukankan      html  css  js  c++  java
  • map容器对象插入数据的4种方式

    #include <string>

    #include <iostream> 

    #include <map> 

    #include <utility> 

    using namespace std;

    int main()

    {

        map<int, string> Employee;

     

       1: //通过键值赋值

        Employee[123] = "Mayuefei";

     

     

      2: //通过成员函数insert和STL的pair赋值

        Employee.insert(pair<int, string>(132, "Liaoyuanqing"));

     

     

       3: //通过value_type赋值

        Employee.insert(map<int, string>::value_type(124, "Liyiyi"));

     

     

      4: //通过make_pair赋值

        Employee.insert(make_pair(234, "LLK.D"));

     

        for (map<int, string>::iterator it = Employee.begin(); it != Employee.end(); it++)

        {

           cout<<(*it).first<<":"<<(*it).second<<endl;//取值操作

     

        }

        system("pause");

        return 1;

    };

    注:只有:通过键值赋值才可二次插入,替换之前插入的值

  • 相关阅读:
    cf B. Vasily the Bear and Fly
    hdu 3339 In Action
    hdu 六度分离
    cf A. Vasily the Bear and Triangle
    cf C. Secrets
    2.19学习笔记|2.20学习笔记
    VAE代码学习
    2.9日学习记录
    deconvolution反卷积(待学习)
    gamma分布学习
  • 原文地址:https://www.cnblogs.com/wuchunming/p/3780677.html
Copyright © 2011-2022 走看看