jalilweb.com

You are here: Home arrow University arrow Programming arrow C++: Save Console Output to a File
  • Decrease font size
  • Default font size
  • Increase font size
C++: Save Console Output to a File Print E-mail
Written by Jalil   
Thursday, 13 March 2008
The most annoying thing when developing console applications (especially under windows) is when you cannot see the entire output when it is too long for the command line window to handle.

The only way around this is to print the output to a file that you can later open and read. You can usually do this by instantiating an output stream and write to it. But there is a simpler and tidier way to achieve that.

Include this line in your Main function:

std::freopen("output.txt", "w", stdout);

What this function does is that it redirects the standard output stream "cout" to the file you specify in its first argument.

Simple, Tidy and Useful.

Comments (1)Add comments
Ranjith wrote on July 10, 2008
Title: ...
Cool tip,Thanks .It saved my daysmilies/smiley.gif
report abuse
vote down
vote up

Votes: +1

Write comment
quote
bold
italicize
underline
strike
url
image
quote
quote
smile
wink
laugh
grin
angry
sad
shocked
cool
tongue
kiss
cry
smaller | bigger

busy
Last Updated ( Monday, 14 April 2008 )
 
< Prev