我有一个预分配的多维字符串数组,声明如下:
std::string test[5][169] = { { },{ },{ },{ },{ } };
我需要创建一个接受如下输入的函数的函数:
{"abc","dac","fab" },{"hbv","acd" },{ "ccd","ahn","agt","atr"},{"are"},{ }
并在数组中放入正确的值(因为我正在分配它);
问题是我无法将2D +数组作为参数传递给C ++中的函数 并且不能像这样分配多维数组:
test= {"abc","dac","fab" },{"hbv","acd" },{ "ccd","ahn","agt","atr"},{"are"},{ };
我正在寻找一种方法将正确的值放入数组中。
我也尝试使用std::vector
,我只解决了一维数组的问题:
std::vector<std::string> test;
test = {"abc","dac","fab" };
但我需要像
这样的东西std::vector< std::vector<std::string> > test;
test = {"abc","dac","fab" },{"hbv","acd" },{ "ccd","ahn","agt","atr"},{"are"},{ };
答案 0 :(得分:1)
在你的最后一行添加一对大括号,你应该完成:
test = {{"abc","dac","fab" },{"hbv","acd" },{ "ccd","ahn","agt","atr"},{"are"},{ }};