【发布时间】:2017-05-25 02:32:30
【问题描述】:
如何在 vscode 上使用 C++11 兼容模式编译?
test.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?错误直接来自 gcc。
-
我添加了我的 gcc 版本,我不确定该版本是否用于编译。我会试试你的建议。
-
我更新了它,有一个错字。您可以通过运行
g++ --version查看当前版本
标签: c++ c++11 visual-studio-code