Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/128.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
初始化C+中字符串向量的向量+; 我试图在C++中做一个向量向量,但我没有得到它;这就是我的代码的样子: #include <vector> #include <string> int main() { std::vector<std::vector<std::string>> foo = { std::vector<std::string> ex, std::vector<std::string> bar, }; } #包括 #包括 int main(){ 向量foo= { std::vector ex, 向量条, }; }_C++ - Fatal编程技术网

初始化C+中字符串向量的向量+; 我试图在C++中做一个向量向量,但我没有得到它;这就是我的代码的样子: #include <vector> #include <string> int main() { std::vector<std::vector<std::string>> foo = { std::vector<std::string> ex, std::vector<std::string> bar, }; } #包括 #包括 int main(){ 向量foo= { std::vector ex, 向量条, }; }

初始化C+中字符串向量的向量+; 我试图在C++中做一个向量向量,但我没有得到它;这就是我的代码的样子: #include <vector> #include <string> int main() { std::vector<std::vector<std::string>> foo = { std::vector<std::string> ex, std::vector<std::string> bar, }; } #包括 #包括 int main(){ 向量foo= { std::vector ex, 向量条, }; },c++,C++,当试图用GCC编译它时,我得到了以下输出: example.cpp: In function ‘int main()’: example.cpp:6:28: error: expected primary-expression before ‘ex’ std::vector<std::string> ex, ^~ example.cpp:6:28: error: expected ‘}’ before ‘ex’ example.cpp

当试图用GCC编译它时,我得到了以下输出:

example.cpp: In function ‘int main()’:
example.cpp:6:28: error: expected primary-expression before ‘ex’
 std::vector<std::string> ex,
                        ^~
example.cpp:6:28: error: expected ‘}’ before ‘ex’
example.cpp:5:2: note: to match this ‘{’
{
^
example.cpp:6:28: error: could not convert ‘{<expression error>}’ from                                                            ‘<brace-enclosed initializer list>’ to ‘std::vector<std::vector<std::__cxx11::basic_string<char> > >’
std::vector<std::string> ex,
                        ^~
example.cpp: At global scope:
example.cpp:9:1: error: expected declaration before ‘}’ token
}
^
example.cpp:在函数“int main()”中:
示例.cpp:6:28:错误:“ex”之前应为主表达式
std::vector ex,
^~
示例.cpp:6:28:错误:在“ex”之前应为“}”
示例.cpp:5:2:注意:要匹配此“{”
{
^
示例.cpp:6:28:错误:无法将“{}”从“”转换为“std::vector”
std::vector ex,
^~
example.cpp:在全局范围内:
示例.cpp:9:1:错误:应在“}”标记之前声明
}
^

任何帮助都将不胜感激。谢谢

在初始化器列表中删除名称:

#include <vector>
#include <string>

int main() {
    std::vector<std::vector<std::string>> foo =
    {
        std::vector<std::string>{}, // <- no name + added curly braces
        std::vector<std::string>{}  // <- no comma
    };
}
#包括
#包括
int main(){
向量foo=
{
std::vector{},//另一种方式:

#include <string>
#include <vector>

int main()
{
  std::vector<std::vector<std::string>> foo(2);
}
#包括
#包括
int main()
{
std::载体foo(2);
}

在定义语句中不能有声明
std::vector foo={{{“hello”,“world”},{“foobar”};
?这个答案可能会有帮助。或者只是
std::vector foo(2);
啊,是的!修复了