map的基本操作——添加、遍历、删除

map map1;

//插入
void mapInsert()
{
	//方法1
	map1.insert(pair(1,"teacher01"));
	map1.insert(pair(1,"teacher02"));

	//方法2
	map1.insert(make_pair(3,"teacher03"));
	map1.insert(make_pair(4,"teacher04"));

	//方法3
	map1.insert(map::value_type(5,"teacher05"));
	map1.insert(map::value_type(6,"teacher06"));

	//方法4
	map1[7]="teacher07";
	map1[8]="teacher08";
}

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

你可能感兴趣的:(STL)