您的位置:首页 > 其它

map的4种插入方式

2017-09-18 18:11 190 查看
#include<string>
#include<iostream> 
#include<map> 
#include<utility> 
usingnamespacestd;
intmain()
{
    map<int,string>Employee;

    //通过键值赋值
    Employee[123] ="Mayuefei";
    //通过成员函数insert和STL的pair赋值
    Employee.insert(pair<int,string>(132,"Liaoyuanqing"));
    //通过value_type赋值
    Employee.insert(map<int,string>::value_type(124,"Liyiyi"));
    //通过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;
};

顶4踩0
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: