#include <iostream>
int main()
{
int a{7}; // it is not supported in VS code
std::cout << a << '\n';
return 0;
}
当我按下run时,终端显示如下命令-
$ cd“ / Users / xxxx / Desktop / C ++ / C ++ /” && g ++ example.cpp -o example &&“ / Users / xxxx / Desktop / C ++ / C ++ /” example
我想在编译时将基本命令更改为此
$ cd“ / Users / xxxx / Desktop / C ++ / C ++ /” && g ++ example.cpp -std = c ++ 17 -o example &&“ / Users / xxxx / Desktop / C ++ / C ++ /“示例
所以我不必每次执行时都键入'-std = c ++ 17'。
tasks.json
{
"version": "2.0.0",
"tasks": [
{
"type": "shell",
"label": "C/C++: g++ build active file",
"command": "/usr/bin/g++",
"args": [
"-g",
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}"
],
"options": {
"cwd": "${workspaceFolder}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
对不起,英语不好。
答案 0 :(得分:0)
将配置更改为:
...
"args": [
"-std=c++17",
"-g",
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}"
],
...
编辑:自从您提到:
我尝试了,什么都没改变。正在执行的命令仍然相同。
可能您的VS Code的配置有问题,您应该考虑删除工作区中的.vscode
文件夹并创建一个新的文件夹。我已经描述了正确的方法in this SO thread。