23

I am debugging c++ console application with Visual studio. I exhausted of inserting the same input every time I debug this program. I would like to use the same input more times.

I do this without debugging in command line with command: Program.exe < 1.in

Is it possible to use debugging with standard input redirected from file???

I already tried looking in to procejt properties. I tried setting Command to $(TargetPath) < 1.in instead of $(TargetPath). I also tried setting Command Arguments to < 1.in. Niether of these method worked.

I am using Visual Studio 2012. But this is probably same in all versions of studio.

Cœur
  • 37,241
  • 25
  • 195
  • 267
user1930362
  • 243
  • 1
  • 2
  • 4
  • I think this is what you're looking for http://stackoverflow.com/questions/298708/debugging-with-command-line-parameters-in-visual-studio – Zeph Dec 26 '12 at 17:49

3 Answers3

40

This is a supported debugging scenario. You do have to make sure that the debugger can find the file. Leave the Command setting at $(TargetPath). A possible value for the Command Arguments setting is:

 < "$(ProjectDir)test.txt"

if the input file "test.txt" is located in the project directory. Or type the full path of the file to be sure. The MSDN article that describes this feature is available here.

Erti-Chris Eelmaa
  • 25,338
  • 6
  • 61
  • 78
Hans Passant
  • 922,412
  • 146
  • 1,693
  • 2,536
  • 1
    Notes: The "Command line arguments" fields that worked for me was: `< test.txt` Where `test.txt` was in the `...///bin/Debug/` Remember to check your _exact_ filename With a command line argument & standard in I had a "Command line arguments" field of: `-hello < test.txt` – 3ygun Feb 07 '18 at 19:20
  • 1
    This is a C++ question. But sure, it works in a C# or VB.NET project as well. – Hans Passant Feb 16 '18 at 07:22
  • In vscode arguments in launch.json should be separated: "program": "${workspaceFolder}/robot_strategy.exe", "args": ["<", "${workspaceFolder}/robot_strategy.in"], – vSzemkel Oct 01 '20 at 09:40
2

I just create a file called stdin.txt in the project 1) set the Build Action to Content 2) Copy to Ouput Directory: Copy if newer

Then when you build stdin.txt is copied to the same folder as the executable.

Then in project properties debug|command line arguements enter the following < stdin.txt

There is no need to use a path macro

0

If you don't want to mess with the the path you can add a new file with a right click on the source files folder in the solution explorer and then paste to it the content from the wanted file. And then change the command argument to the new file name.

serj
  • 508
  • 4
  • 20