stl中map的使用

搞不懂他们为何喜欢用pair刚刚在vs2010中测试了map。插入数据和查询数据的方法:测试

    

        map<string,HWND> m;
	HWND hh = NULL;
	std::pair<string,HWND> p;
	p.first = "a";
	p.second = hh;
	m["a"] = hh; 
	HWND hwnd = m["a"];
	if (hwnd)
	{
		cout<<"hello world"<<std::endl;
	}
//下面的方式明显简单多了
	map<string,int> m2;
	m2["a"] = 21;
	int s = m2["a"];
	map<int,string> m3;
	m3[2] = "asd";
	//遍历仍是同样
	map<string,int>::iterator   it=m2.begin();   
	for(;it!=m2.end();++it)   
		cout<<"key:"<<it->first   
		<<"value:"<<it->second<<std::endl;
相关文章
相关标签/搜索