gpt4 book ai didi

c++ - 在 vscode 上编译错误。类型说明符是 C++11 扩展

转载 作者:行者123 更新时间:2023-11-28 05:08:07 26 4
gpt4 key购买 nike

如何在 vscode 上使用 C++11 兼容模式进行编译?

测试.cpp

#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();
}

tasks.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"],

但是,真的,考虑升级。

引用:https://gcc.gnu.org/gcc-4.8/cxx0x_status.html

关于c++ - 在 vscode 上编译错误。类型说明符是 C++11 扩展,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44171350/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com