c - 在 Visual Studio Code 中保存后自动运行可执行文件

标签 c visual-studio-code

我想使用visual studio code进行C编程,我想自动化保存->编译->运行的过程。目前我安装了 MinGW 并使用 C/C++ 扩展我使用 Ctrl+S 实现了保存和编译(我更改了编译的快捷方式)但是为了执行我需要转到 cmd 提示符并执行程序。

有什么方法可以使用一个按钮实现这一目标吗?

最佳答案

我最接近答案的是定义我的快捷方式

[
   {
       "key": "ctrl+s",          
       "command": "workbench.action.tasks.build" 
   },
   {
       "key": "ctrl+d",          
       "command": "workbench.action.tasks.test" 
   }
]

然后在tasks.json中

{
   "version": "0.1.0",
   "command": "cmd",
   "isShellCommand": true,
   "args": ["/C"],
   "showOutput": "silent",
   "tasks": [
       {
           "taskName": "saveNcompile",
           "suppressTaskName": true,
           "isBuildCommand": true,
           "args": ["gcc main.c -o main.exe"]
       }, {
           "taskName": "execute",
           "suppressTaskName": true,
           "isTestCommand": true,
           "args": ["main.exe"]
       }
   ]
}

现在使用 ctrl+s 保存并编译和 ctrl+d 执行。

关于c - 在 Visual Studio Code 中保存后自动运行可执行文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39304595/

相关文章:

c - 用 C 语言生成一个完美的迷宫

visual-studio-code - 如何在 Visual Studio Code 中自动导入库?

visual-studio-code - 如何在 VSCode 扩展的命令面板中输入文本

c - Solaris sparc 和 Solaris x86 之间的结构大小差异

c++ - 简单的 "Hello World"程序在 VS 代码中给出段错误

python - 如何在 VS 代码的 node.js 应用程序中使用 python 包时导入它

visual-studio-code - VS 代码 : Autocomplete in Debug Console only works with Tab, 未输入

c - 为什么我不能从我的循环中捕获这些 KeyPress/KeyRelease 事件?

c - 关于空指针和赋值 C

C sleep 功能不起作用