我对cpp编程很陌生,我正在使用Visual代码作为我的IDE/编辑器。我创建了一个自定义构建任务,它构建当前的活动文件(在我正在处理的编辑器中打开的文件)。下面是我的taks.json。
{
"version": "2.0.0",
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: g++-10 build active file",
"command": "/usr/local/bin/g++-10",
"args": [
//"-g", // include to add debugging support
"-O2",
"${file}",
"-o",
//"${fileDirname}/${fileBasenameNoExtension}"
"build/${fileBasenameNoExtension}"
],
"options": {
"cwd": "${workspaceFolder}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "compiler: /usr/local/bin/g++-10"
},
{
"type": "cppbuild",
"label": "C/C++: g++-10 run active file",
"command": "${workspaceFolder}/build/${fileBasenameNoExtension}",
"args": [],
"options": {
"cwd": "${workspaceFolder}"
},
"problemMatcher": [
"$gcc"
],
"group": "none",
"detail": "compiler: /usr/local/bin/g++-10"
}
]
}和launch.json
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "g++-10 - Build and debug active file",
"type": "cppdbg",
"request": "launch",
"program": "build/${fileBasenameNoExtension}",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "lldb",
// "preLaunchTask": "C/C++: g++-10 build active file"
}
]
}我能够运行构建任务来生成cpp对象文件。但是如何运行刚在IDE中构建的文件呢?本质上,我只是想模仿build and run来快速检查程序。我尝试创建一个新任务(tasks.json的“任务”中的第二项),但是当运行时,它不起作用。我试着在网上找到,但没有结果。
目前,我使用此任务构建文件,然后切换到terminal并运行该文件。这个工作流是可以的,但是如果实现了这一点,我就可以像在公共IDE中支持的那样执行build and run了。有办法做到这一点吗?
谢谢!
为F5调试问题附加屏幕片段。




发布于 2021-05-21 17:39:31
若要使用调试会话从标准输入读取,必须从文本文件重定向标准输入。
要重定向标准输入,需要这样的命令
program_name < input.txt所以您必须将这些命令添加到您的启动中。
"args": [
"<",
"input.txt"
],发布于 2021-05-21 18:47:39
在launch.json变化中
"externalConsole": false,至
"externalConsole": true,https://stackoverflow.com/questions/67640539
复制相似问题