您好,登錄后才能下訂單哦!
void TestMap() { map<string, int> m; m.insert(pair<string, int>("sort", 1)); m.insert(pair<string, int>("sort", 2)); m.insert(pair<string, int>("quick", 5)); m.insert(pair<string, int>("hash", 1)); m.insert(pair<string, int>("map", 1)); m.insert(pair<string, int>("set", 1)); map<string, int>::iterator it = m.begin(); while (it != m.end()) { cout<<"key:"<< it->first.c_str() << " value:"<<it->second<<endl; ++it; } cout << endl; }
模擬字典
typedef map<string, string> DictMap; typedef DictMap::iterator DictMapIter; map<string, string> dict; dict.insert(pair<string, string>("sort","排序")); dict.insert(pair<string, string>("hash", "哈希")); dict.insert(pair<string, string>("test", "測試")); dict.insert(pair<string, string>("erase", "錯誤")); /*pair<DictMapIter, bool> ret = dict.insert(pair<string, string>("erase", "刪除"));*/ //修改value的兩種方式 //1. //DictMapIter ret = dict.find("erase"); //if (ret != dict.end()) //{ // //ret->first = "delete"; // ret->second = "刪除"; //} //2 dict["erase"] = "刪除"; dict["erase"] = "錯誤"; dict["delete"]; //T() dict["delete"] = "刪除";
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。