map容器的四种插入元素方法
来源:互联网 发布:金蝶餐饮软件 编辑:程序博客网 时间:2024/06/02 05:29
//插入元素 //四种插入方法比较void display(){map<int,string> m;pair<map<int,string>::iterator,bool> pair1 ,pair2,pair3;//1.方法 pair1 = m.insert(pair<int,string>(1,"teacher01"));pair2 = m.insert(pair<int,string>(2,"teacher02"));pair3 = m.insert(pair<int,string>(2,"teacher02"));if (pair2.second){cout<<"2 teacher02插入成功"<<endl;cout<<pair2.first->first<<":"<<pair2.second<<endl;}else{cout<<"2 teacher02插入失败"<<endl;cout<<pair2.first->first<<":"<<pair2.second<<endl;}if (pair3.second){cout<<"2 teacher02插入成功"<<endl;cout<<pair3.first->first<<":"<<pair3.second<<endl;}else{cout<<"2 teacher02插入失败"<<endl;cout<<pair3.first->first<<":"<<pair3.second<<endl;}//2.方法 m.insert(make_pair(3,"teacher03"));m.insert(make_pair(4,"teacher04"));//3.方法 m.insert(map<int,string>::value_type(5,"teacher05"));m.insert(map<int,string>::value_type(6,"teacher06"));//4. 如果key相等 会修改对应的value m[7] = "teacher07";m[8] = "teacher08";m[0] = "teacher09";m[0] = "teacher00";//遍历for (map<int,string>::iterator it = m.begin();it!=m.end();it++){cout<<(*it).first<<endl;cout<<(*it).second<<endl;}while (!m.empty()){map<int,string>::iterator it = m.begin();cout<<it->first<<"\t"<<it->second<<endl;m.erase(it);}}
0 0
- map容器的四种插入元素方法
- map容器元素的三种插入方式
- STL中map容器的元素插入
- c++ map容器的元素插入
- map容器插入数据的4种方法
- map容器(4种元素添加方法的异同)
- stl中map的四种插入方法总结
- map容器的三种插入方式
- Map四种获取key和value值的方法,以及对map中的元素排序
- Map四种获取key和value值的方法,以及对map中的元素排序
- Map四种获取key和value值的方法,以及对map中的元素排序
- map中元素的插入
- map元素的插入方式
- map的四种遍历方式,map遍历元素
- map容器创建、元素插入和前向遍历访问
- map容器对象插入数据的4种方式讲解
- map容器对象插入数据的4种方式
- map容器对象插入数据的4种方式讲解
- web.xml配置文件中<async-supported>true</async-supported>报错的解决方案
- Python存储数据库时候随机数的问题
- 9-28日[Cordova在iOS端的微信三方插件分解]
- 对 A label propagation method using spatial-spectral consistency *** 的理解
- 编译时错误
- map容器的四种插入元素方法
- JSON.parse()和JSON.stringify()
- 第六周项目2
- 第五周 项目一 建立顺序栈算法库
- "人脉"是麻烦出来的!
- MapReduce优化
- 网页推送技术选择
- 本地创建FTP服务器(Win7)
- linux下处理僵尸进程