gpt4 book ai didi

c++ - 使用 vs 代码调试文件时,如何将文件传递到我的程序中

转载 作者:行者123 更新时间:2023-12-03 06:52:29 24 4
gpt4 key购买 nike

我想用传入的文件启动 a.exe(一个编译的 cpp 程序)。在 CMD 上,我会这样做 a.exe < input.txt .如何在 Debug模式下使用 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我已经尝试使用 "<", "input.txt"就像在 this post"<input.txt"正如 this post 中所建议的.两者都不起作用。按照建议在 cmd 上调试 here似乎是一个非常糟糕的做法。当我有很棒的 vs code 调试工具时,为什么要在 cmd 上调试?

我在 Windows 机器上运行。

最佳答案

您缺少的是告诉 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"
}
]
}

关于c++ - 使用 vs 代码调试文件时,如何将文件传递到我的程序中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49834762/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com