我想要一個std :: pair並使用std :: map將其映射到std :: string。它的工作方式被賦予一個由char和一個字符串組成的對,將它映射到一個特定的字符串。如何使用std :: map將字符串和字符對映射到字符串?
這種設置到目前爲止工作得很好(編譯器接受它):
std::map<std::pair<char, std::string>, std::string> mymap;
std::map<std::pair<char, std::string>, std::string>::iterator it;
但是,當我嘗試這樣做:
mymap['a', "Q1"] = "Q4";
mymap['b', "Q2"] = "Q3";
mymap['c', "Q3"] = "Q2";
mymap['d', "Q4"] = "Q1";
它回來的這個錯誤,我不明白:
Error 1 error C2679: binary '[' : no operator found which takes a right-hand operand of type 'const char [3]' (or there is no acceptable conversion)
,它是(四個行代碼的左支架下相關聯的錯誤,其中一個紅平方Uiggly出現)
有人可以幫助我瞭解我做錯了什麼嗎?
是否像mymap [{'a',「Q1」}] =「Q4」; – user1438832