首页 > 解决方案 > 用于编译和运行 .c 文件的 Visual Studio Code 任务

问题描述

如何在 Visual Studio Code(最新版本)中创建任务来编译和运行 .c 文件。
我在网上找到了这个:

    "version": "2.0.0",
    "tasks": [
        {
            "label": "compile and run C",
            "type": "shell",
            "command": "(gcc -g ${file} -o ${fileBasenameNoExtension}) -and (./${fileBasenameNoExtension})",
            "presentation": {
                "reveal": "always",
                "panel": "shared"
            },
            "group": {
                "kind": "build",
                "isDefault": true
            }
        }
    ]
}

我设法对其进行了调整,但它仍然不会同时编译和运行,而是得到了这个:

> Executing task: (gcc -g d:\ISEP\ARQCP\partilha\arqcp19202deg01\pl0_7.c -o pl0_7) -and (./pl0_7) <

False

Terminal will be reused by tasks, press any key to close it.

有什么方法可以使用简单的快捷方式编译和运行我的代码(目前我按 CTRL+SHIFT+B 来“编译并运行”)?

标签: cvisual-studiocompilationtask

解决方案


所以我一直在寻找一种方法来做到这一点,我发现了这个简单的扩展:Code Runner

基本上,它只是为大多数编码语言添加了一个运行代码按钮,它使它变得如此容易。


推荐阅读