提问者:小点点

VS代码:编译时更改命令行


Program:VS Code 1.47.3
包,使用:https://marketplace.visualstudio.com/items?itemname=ms-vscode.cpptools

#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++/”示例

我想在编译时将基本命令更改为

$cd“/users/xxxx/desktop/C++/C++/”&& G++示例。cpp-std=C++17-O示例&& “/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
            }
        }
    ]
}

抱歉,英语不好。


共1个答案

匿名用户

将配置更改为:

...
"args": [
    "-std=c++17",
    "-g",
    "${file}",
    "-o",
    "${fileDirname}/${fileBasenameNoExtension}"
],
...

编辑:既然你提到了:

我试过了,但什么都没有改变。 执行的命令仍然是相同的。

可能您的VS代码的配置有问题,您应该考虑删除工作区中的.vscode文件夹& 创建一个新的。 我在这条线上描述了正确的方法。