如何使用 Visual Studio 2010 进行输入重定向?
我有一个 input.txt 文件。在该文件中,有一系列对,例如:
interactive 300
cpu 200
disk 400
real-time 500
tty 300
disk 200
在制作程序时,我打开了一个名为 input.txt 的文件,并使用 fstream 读取所有这些对。 我现在的问题
infile >> string1 >> int1
是,如何让视觉工作室使用 input.txt 文件进行输入重定向。我已经将所有 infile 实例更改为 cin,正如我相信我应该做的那样。我进入项目>属性>调试>命令参数并输入:
< input.txt
但这仅当我从 Visual Studio 中运行它时才有效。当我编译它时,转到exe所在的文件夹,将输入文件放入该文件夹中并运行exe,没有任何反应。我刚刚得到一个带有闪烁 _ 的 cmd 窗口。
感谢您对任何人的帮助:)
I have an input.txt file. In that file, there are a series of pairs such as:
interactive 300
cpu 200
disk 400
real-time 500
tty 300
disk 200
While making the program I had opened a file called input.txt and used the fstream to read in all of these pairs. Something like
infile >> string1 >> int1
my question now is, how do I get visual studios to do input redirection with the input.txt file. I've gone and changed all my instances of infile to cin, as I believe i'm supposed to do. I went into Project > Properties > Debugging > Command arguments and typing in :
< input.txt
But that only works when I run it from within visual Studios. When I compile it, go to the folder where the exe is, place the input file in that folder and run the exe, nothing happens. I just get a cmd window with a blinking _ .
Thanks for the help to anyone that does :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
它正在等待您输入一些内容。您必须通过输入“yourapp <
It is waiting for you to type something. You have to start it by typing 'yourapp < input.txt' at the command line. Or you can type in the lines that are now in the file, finish with Ctrl+Z.
仅当您使用“运行”命令通过 Visual Studio 运行可执行文件时,在 Visual Studio 中输入命令参数的内容才有效。这些设置根本不与可执行文件一起保存。
您必须提供
<在命令窗口中输入.txt
。如果您希望单击图标来启动程序,则可以将命令放入批处理 (.bat
) 文件中,并使用批处理文件的链接。The things you type into command arguments in Visual Studio only work when you run the executable through Visual Studio, using the Run command. Those settings are not saved with the executable at all.
You have to provide the
< input.txt
at a command window. If you'd rather click on an icon to launch the program instead, you can put the command into a batch (.bat
) file and use a link to the batch file.