开发者

How to do input redirection using Visual Studio 2010?

I have an input.txt file. In that file, there are a serie开发者_JS百科s 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 :)


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜