C++ standard input from file when debugging from IDE

半腔热情 提交于 2019-12-23 12:22:16

问题


I'm using VS 2010, and I'm wondering how I can get my c++ program to read a file using standard input while debugging. I know how to do it from command prompt, but not when debugging.

Basically I want it to read in a file with cin>> instead of me typing stuff - but in debug mode.


回答1:


If you go into the project's Properties, under Debugging there's a set of options for how to actually launch the process. IIRC the way to do this is to put:

< yourfile.txt

In the Command Arguments box.




回答2:


I've never tried this (I'll usually have a debug path that accepts input from a file), but this MS Connect bug report claims that redirection operators worked in VS2005 but stopped working in VS2008:

  • http://connect.microsoft.com/VisualStudio/feedback/details/333493/cant-redirect-stdin-stdout-for-debugging

I am debugging a console application that uses stdin & stdout, which are expected to be redirected to files. I use "<" and ">" in the Command Arguments in the Debugging Configuration Properties to redirect stdin and stdout. However, when I start debugging stdin comes from the console and stdout prints at the console. This worked correctly in VS2005 and should still work per VS2008 Help.

MS claims to have fixed the problem at some point, so maybe it's working again in 2010?




回答3:


Right-click on the project in the Solution Explorer and go to Properties. Then click on "Debugging" on the left and in the "Command Arguments" box type something like < input.txt



来源:https://stackoverflow.com/questions/2596522/c-standard-input-from-file-when-debugging-from-ide

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!