map容器的四种插入元素方法

//插入元素 //四种插入方法比较
void display()
{
	map m;

	pair::iterator,bool> pair1 ,pair2,pair3;

	//1.方法 
	pair1 = m.insert(pair(1,"teacher01"));
	pair2 = m.insert(pair(2,"teacher02"));
	pair3 = m.insert(pair(2,"teacher02"));

	if (pair2.second)
	{
		cout<<"2 teacher02插入成功"<first<<":"<first<<":"<first<<":"<first<<":"<::value_type(5,"teacher05"));
	m.insert(map::value_type(6,"teacher06"));

	//4. 如果key相等 会修改对应的value 
	m[7] = "teacher07";
	m[8] = "teacher08";
	m[0] = "teacher09";
	m[0] = "teacher00";

	//遍历
	for (map::iterator it = m.begin();it!=m.end();it++)
	{
		cout<<(*it).first<::iterator it = m.begin();
		cout<first<<"\t"<second<

你可能感兴趣的:(C++提高)