我尝试像这样编辑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 拖到终端时,它运行成功。但有什么办法可以自动运行它吗?无需拖动它。
可以通过多种方式编译运行。这是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 扩展:
如:
安装后,“CompileRun”有几个命令面板选项,可以使用默认/自定义选项编译/运行,也可以使用 F6/F7 快捷键。
其他几个类似的扩展也执行相同的操作。在扩展市场中搜索“c/c++ run”。
3.老办法:
只需在 VS Code 中打开一个新终端并以老式方式运行可执行文件;-)
./a.out