Ok so for my program it prompts the user to enter 32 bits each separated by a space.

But while debugging I would like to be able to load a txt file or something that contains the 32 bits instead of having to enter it each time I test it.

How can I do this? (I know in gcc its a.out < input.txt);

Dani AI

Generated

Short answer: you can either run the built EXE from a shell and feed it a file, or make Visual Studio run the EXE in the folder that contains your input file, or change the program to open the file itself. was on the right track about the EXE/working-directory; the details below make that easy and repeatable.

Set the working folder used while debugging so the input file sits where the program expects it. In Project Properties -> Configuration Properties -> Debugging set Working Directory to a folder you control (for example $(ProjectDir) or $(OutDir)). To copy the test file into the output folder automatically, add a post-build step such as:

copy /Y "$(ProjectDir)input.txt" "$(OutDir)"

If you want to use shell input redirection while hitting F5, change Debugging -> Command to cmd.exe and put a command like this into Command Arguments so the shell performs the redirection:

/C "$(TargetPath)" < "$(ProjectDir)input.txt"

A code-side option is to redirect stdin at program start for debug builds:

#ifdef _DEBUG
freopen("input.txt", "r", stdin);
#endif

This reads the file as if typed, but remember to guard or remove it for release builds. Confirm which configuration (Debug vs Release) Visual Studio built and where $(OutDir) points before running. For quick manual testing, running the program from a normal command prompt in the output folder also works; pointed to resources that explain basic shell use if needed.

Recommended Answers

All 5 Replies

cool. And it's from RPI. I got to UAlbany

How can I do this? (I know in gcc its a.out < input.txt);

It's the same on the Windows command line.

which directory do I put it in? it's not working

You have to find the directory the .EXE is in and set the command window into that location. Then create the file there too.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.