我想启动一个带有文件的a.exe(已编译的cpp程序)。在CMD上我会像a.exe < input.txt
那样做。如何在调试模式下使用VS Code启动它?
这是我的launch.json文件:
{
"version": "0.2.0",
"configurations": [
{
"name": "C++ Launch",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceRoot}/a.exe",
"args": [
"<",
"input.txt"
],
"stopAtEntry": false,
"cwd": "${workspaceRoot}",
"environment": [],
"externalConsole": true,
"miDebuggerPath": "C:\\MinGW\\bin\\gdb.exe",
"linux": {
"MIMode": "gdb"
},
"osx": {
"MIMode": "lldb"
},
"windows": {
"MIMode": "gdb"
}
}
]}
作为args
,我已尝试按照this post和"<", "input.txt"
中this post的建议使用"<input.txt"
。两者都不起作用。按照建议here调试cmd似乎是一种非常糟糕的做法。当我拥有vs代码的强大调试工具时,为什么要在cmd上进行调试?
我在Windows机器上运行。
答案 0 :(得分:0)
您缺少的是告诉gdb文件的实际位置。尝试提供输入文件时,您需要将文件的位置放在引号中,因此看起来像这样:
{
"version": "0.2.0",
"configurations": [
{
"name": "g++ - Build and debug active file",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}/${fileBasenameNoExtension}",
"args": [
"<", "${fileDirname}/words5.txt"
],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "C/C++: g++ build active file",
"miDebuggerPath": "/usr/bin/gdb"
}
]
}