C++map用法

#include 
#include 
using namespace std;
int main(){
	map map1;
	map1.insert(map::value_type(1, "Anna"));//map的插入
	map1.insert(map::value_type(2, "aaa"));
	map1.insert(map::value_type(3, "mmmm"));
	map1[4]="huode";//添加元素
	map::iterator iter_map=map1.begin(); //取得迭代器首地址
	int key= iter_map->first; //取得键
	 string value = iter_map->second;       //取得value
	 map1.erase(3); //根据key删除value 
	 //遍历
	 for(map::iterator iter = map1.begin();iter!=map1.end();iter++){
	 	int key1=iter->first;
	 	string s=iter->second;
	 	cout<

 

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