|
-
March 11th, 2009, 12:05 PM
#1
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!
-
March 11th, 2009, 12:22 PM
#2
Re: How to output in a .txt file?
Victor Nijegorodov
-
March 11th, 2009, 12:31 PM
#3
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.
-
March 11th, 2009, 12:43 PM
#4
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.
-
March 11th, 2009, 12:51 PM
#5
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
Nobody cares how it works as long as it works
-
March 11th, 2009, 11:48 PM
#6
Re: How to output in a .txt file?
You probably can use SetStdHandle with a handle to the .txt file opened in write mode.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|