Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/visual-studio-code/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Build 如何在visual studio代码中自动运行.out文件?_Build_Visual Studio Code_G++ - Fatal编程技术网

Build 如何在visual studio代码中自动运行.out文件?

Build 如何在visual studio代码中自动运行.out文件?,build,visual-studio-code,g++,Build,Visual Studio Code,G++,我尝试像这样编辑tasks.json文件 { "version": "2.0.0", "tasks": [ { "label": "build hello world", "type": "shell", "command": "g++", "args": [ "-g", "helloworld.cpp" ],

我尝试像这样编辑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.拖到终端时,它会成功运行。但是有什么方法可以自动运行它吗?无需拖动它。

您可以通过各种方式编译和运行。以下是三点:

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代码扩展:

例如:

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

其他几个类似的扩展也这样做。在扩展市场中搜索“c/c++运行”

3。老式方式:

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

./a.out