How to output in a .txt file?
Hi,
I have a programme that shows me a lot of values in the console. I would like to have the output information in a .txt file?
Can somebody explain me in a simple way how I can do this? Which commands do I have to add exactly?
I'd be grateful for answers!
Re: How to output in a .txt file?
Re: How to output in a .txt file?
If you're primarily using printf, open a file with fopen and write to it instead with fprintf().
If you're primarily using cout, open a an ofstream and write to it instead of cout.
Re: How to output in a .txt file?
Additionally,
1) you can run from the command prompt :
your_code.exe >output.txt
2) If using cout, you can redirect the output by appropriately
setting its rdbuf() to that of a file's rdbuf(). The main
advantage in this message is that you can switch between
outputting to the console or to the file at any time during
the running of the code.
Re: How to output in a .txt file?
Some error messages may be output to the stderr stream.
IIRC, you can redirect both stdout and stderr to file using.
Code:
prog.exe >2> out.txt
or possibly
Code:
prog.exe 1>2> out.txt
Re: How to output in a .txt file?
You probably can use SetStdHandle with a handle to the .txt file opened in write mode.