[英]Compile error on vscode. type specifier is a C++11 extension
如何在vscode上使用C ++ 11兼容模式进行编译?
测试文件
#include <iostream>
using namespace std;
void print()
{
int v[] = {0,1,2,3,4,5,6,7,8,9};
for (auto x : v) {
cout << x << '\n';
}
for (auto x : {10,21,32,43,54,65}) {
cout << x << '\n';
}
}
int main() {
print();
}
task.json
{
"version": "0.1.0",
"command": "g++",
"isShellCommand": true,
"args": ["-O2", "-g", "test.cpp"],
"showOutput": "always"
}
错误
test.cpp:8:10: warning: 'auto' type specifier is a C++11 extension [-Wc++11-extensions]
for (auto x : v) {
更新1
$ gcc -v
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 7.3.0 (clang-703.0.31)
Target: x86_64-apple-darwin15.6.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
听起来像gcc的旧版本。 你应该升级!
您可以通过更改来使其工作
"args": ["-O2", "-g", "test.cpp"],
至
"args": ["-std=c++11", "-O2", "-g", "test.cpp"],
但是,实际上,请考虑升级。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.