Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
您好,这是我第一次使用 STL 地图,我想知道如何在地图中添加新条目。
这是我的代码:
map<string, Account *> accounts; string key = "blah"; accounts[key] = Acc; error: expected primary-expression before ‘;’ token
我应该使用 .insert() 函数还是这种方法相同?
我解决了以下问题
Account* Acc; Acc = new Account(args);
*之后的 Acc真的没有任何必要。编译器已经知道它是一个指针,因为您将它声明为一个。
*
map<string, Account *> accounts; Account* Acc = ...; string key = "blah"; accounts[key] = Acc; // Fine