如何在 Visual Studio Code 中自动运行 .out 文件?

问题描述 投票:0回答:1

我尝试像这样编辑tasks.json文件

{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "build hello world",
            "type": "shell",
            "command": "g++",
            "args": [
                "-g", "helloworld.cpp"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            }
        }
    ]
}

结果是a.out.dSYM和a.out文件。当我将 a.out 拖到终端时,它运行成功。但有什么办法可以自动运行它吗?无需拖动它。

build visual-studio-code g++
1个回答
0
投票

可以通过多种方式编译运行。这是3:

1。添加一个任务来运行您的可执行文件。

类似:

{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "build hello world",
            "type": "shell",
            "command": "g++",
            "args": [
                "-g", "helloworld.cpp"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            }
        },
        {
            "label": "build and run hello world",
            "type": "shell",
            "command": "${workspaceFolder}/a.out",
            "dependsOn": "build hello world"
        }
    ]
}

2。使用 Visual Studio Code 扩展:

如:

C/C++编译运行

安装后,“CompileRun”有几个命令面板选项,可以使用默认/自定义选项编译/运行,也可以使用 F6/F7 快捷键。

其他几个类似的扩展也执行相同的操作。在扩展市场中搜索“c/c++ run”。

3.老办法:

只需在 VS Code 中打开一个新终端并以老式方式运行可执行文件;-)

./a.out
© www.soinside.com 2019 - 2024. All rights reserved.