如何使用插入方法的统一初始化来填充地图



我有这样的东西

std::unordered_map<int, std::unordered_map<int, std::string>> p;

我正在尝试这个

p.insert({ 0x00 ,{0x03,"Custom"} });

没有重载函数的实例...获取参数列表错误 谁能告诉我正确的语法?

缺少一对牙套。p的值是集合 -unordered_map,因此通过在0x00处插入作为键,您可以将集合放在例如由 2 个项目组成的集合中,语法为:

p.insert({ 0x00 , { {0x03,"Custom"},{0x04,"Custom2"} } });
^ ^brace for item ^brace for item  ^
|->begin collections               |-> end collections

因此,当集合有一个项目时,语法应为:

p.insert({ 0x00 , { {0x03,"Custom"} } });

最新更新