将输入管道输入到 C++ 程序中以在 Visual Studio 中进行调试

之前可能有人问过这个问题,但到目前为止我还没有找到任何答案.我正在尝试使用多行输入启动我的程序,即我不想每次都在命令行中输入一些东西(因为我可能会犯错误).我查看了命令行参数并将我的输入粘贴到那里,但它把它解释为每一行都是一个命令.

this has probably been asked before, but I haven't been able to find any answers so far. I'm trying to start my program up with multi-line input, I.E. something I don't want to type in the command line every time (as I'd probably make a mistake). I looked into the command line arguments and I pasted my input in there, but it interpreted it as every line being a command.

输入以防万一:

8
c j i b s x k j
t a o a v y z l
x r t s w o n m
z y x e n s p r
l l o b s t e r
t g x a a a a a
j p e l a k e k
t r s l j e e e
cat
test
baseball
bake
paste
lobster
stake
zen
locks
rake
gel
slack
jar
dinosaur
0

推荐答案

将数据放入文件中,然后转到 Visual Studio 中的项目属性并选择调试"类别.

Put your data in a file then go to the project properties in Visual Studio and select the "Debugging" category.

在命令参数"属性类型中:

In the "Command Arguments" property type:

< "path/to/the/file"

现在,当调试器启动或使用 Ctrl-F5 在 Visual Studio 中(但没有调试器)启动程序时,该文件将通过标准输入提供给程序.

Now that file will be fed to the program via standard input when the debugger is launched or when you launch the program within Visual Studio (but without the debugger) using Ctrl-F5.

如果希望测试文件随项目一起移动,可以使用VS宏来指定项目目录等.

You can use VS macros to specify the project directory, etc. if you want the test file to move along with the project.

相关文章