刚开始学习C++,在使用vector的过程中,发现编译出现错误,出错的代码行为:
vector<string> a1 = {"a", "b", "c"};
具体错误信息为:
non-aggregate type 'vector<std::string>' (aka 'vector<basic_string<char> >') cannot be initialized with an initializer list
翻阅有关资料,发现列表初始化vector对象,属于C++11标准。因此,在使用g++进行编译的时候,需要特别开启C++11标准编译选项:-std=c++11。
g++ -std=c++11 -o test test.cpp
编译通过。