【发布时间】:2015-07-25 09:58:18
【问题描述】:
我在 c++ 中有这个特殊的字符串数组:
#include <map>
#include <string>
std::map<std::string, std::map<int, std::string>> oParam;
oParam["pA"][0] = "a";
oParam["pA"][1] = "b";
oParam["pA"][2] = "c";
oParam["pB"][0] = "x";
oParam["pB"][1] = "y";
oParam["pB"][2] = "z";
但我想用初始化列表对其进行初始化,如下所示:
std::map<std::string, std::map<int, std::string>> oParam{
{ "pA", { "a", "b", "c" } },
{ "pB", { "x", "y", "z" } },
};
但这给了我一个错误。我是否缺少一些括号?
【问题讨论】:
标签: c++ string multidimensional-array