搞不懂他们为什么喜欢用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;