在使用 vs 代码调试文件时,如何将文件传递到我的程序中
How can I pass a file into my program, when debugging it with vs code
我想启动一个.exe(一个编译的cpp程序),并将一个文件传递给它。在 CMD 上,我会像a.exe < input.txt
一样做.如何在调试模式下使用 VS Code 启动它?
这是我的启动.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"
,就像这篇文章中建议的那样,"<input.txt"
这篇文章中的建议。两者都不起作用。如此处建议的那样,在 cmd 上进行调试似乎是一种非常糟糕的做法。当我拥有 vs 代码的出色调试工具时,为什么要在 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"
}
]
}
另一种选择是在 a.cpp 文件中添加这些行。
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
所有 cin 和 cout 都将使用输入.txt和输出.txt。
相关文章:
- 在C++程序中输入的文本文件将不起作用,除非文本被复制和粘贴
- C++ Windows 驱动程序MSB3030无法复制该文件,因为它找不到
- 使用mongocxx驱动程序时包含头文件问题
- 使用VerQueryValue检索应用程序的文件描述
- 编译多文件C++程序
- Visual C 32位整数从文件到8位字符到文件 - 程序在某些整数上崩溃
- 文件程序不会停止显示垃圾值
- 简单的QT从文本文件程序中读取不编译
- 从文件 C++ 程序读取停止工作
- C++ - 需要有关如何正确设计多文件程序的建议
- C++文件 I/O - 程序挂起
- 简单的文件 I/O 程序C++
- 有一个简单的程序文件/程序文件(x86)指令的c++在windows
- 配置文件c++程序在perf
- 从同一文件夹读取文件(c++程序)
- 单文件程序的未定义虚函数表
- 无法用多文件程序创建SDL线程
- 我的第一个多文件C++程序不断给我错误消息
- 配置文件C++程序基于墙上的时钟时间与英特尔Vtune放大器
- c++复制文本文件程序使用头文件