map容器对象插入数据的4种方式
2014-06-10 20:34
459 查看
#include<string>
#include<iostream>
#include<map>
#include<utility>
usingnamespacestd;
intmain()
{
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>::iteratorit = Employee.begin(); it != Employee.end(); it++)
{
cout<<(*it).first<<":"<<(*it).second<<endl;//取值操作
}
system("pause");
return 1;
};
注:只有:通过键值赋值才可二次插入,替换之前插入的值
#include<iostream>
#include<map>
#include<utility>
usingnamespacestd;
intmain()
{
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>::iteratorit = Employee.begin(); it != Employee.end(); it++)
{
cout<<(*it).first<<":"<<(*it).second<<endl;//取值操作
}
system("pause");
return 1;
};
注:只有:通过键值赋值才可二次插入,替换之前插入的值
相关文章推荐
- map容器对象插入数据的4种方式
- map容器对象插入数据的4种方式讲解
- map容器对象插入数据的4种方式讲解
- map容器对象插入数据的4种方式讲解
- map容器对象插入数据的4种方式讲解
- map容器插入数据的4种方法
- map容器插入数据之 map[] 和 insert 方式的分析
- map容器元素的三种插入方式
- hibernate系列二:hibernate中java对象的三种状态及数据更新的4种方式
- java方式的将java对象以及list或者map转化为json数据,json转换为object或者map
- mybatis以map的方式批量插入list集合数据操作步骤
- java方式的将java对象以及list或者map转化为json数据 .
- map的4种常见的插入元素的方式及区别
- 遍历map集合对象的4种方式
- map的4种常见的插入元素的方式及区别
- java方式的将java对象以及list或者map转化为json数据
- map容器的三种插入方式
- map的4种插入方式
- map关联容器问题,内部数据按照键值的大小排序,无论插入数据的顺序!
- STL中map容器的元素插入方式