我的是ubuntu下编译c++ primer plus的这么一段程序
#include
#include
using namespace std;
int main()
{
string str("abcd"):
for(auto c : str)
cout << c << endl;
}
报错提示如下:
warming:auto changes meaning in C++11;please remove it [-Wc++0x-compat]
error:c dose not name a type
warming:range-based for loop without a type-specifier only available with -std=c++1z or -std=gnu++1z
我觉得是不支持c++11的auto才引发的一系列错误,但是不知道如何改
LIBS = -std=c++11
之后LIBS加入到编译项里面去
你要是有ide的话,在编译选项里面找找c++ 11支持是否勾选。如果是命令行,那么去掉[-Wc++0x-compat]
g++ -std=c++1z -o test xxx.cpp