搞不懂他們爲何喜歡用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;