Article ID: 58667 - Last Review: April 28, 2005 - Revision: 4.0 How to redirect stdout to a file from a Visual C/C++ programThis article was previously published under Q58667 On This PageSUMMARY This article explains how to redirect stdout to a file from
a C program, then restore the original stdout at a later point in the same
program. The C function typically used to redirect stdout or stdin is
freopen(). To redirect stdout to a file called FILE.TXT, use the following
call: freopen( "file.txt", "w", stdout ); To return stdout to the display (the default stdout), use the following call: freopen( "CON", "w", stdout ); Below is a short program to demonstrate the redirection of stdout: Sample CodeAPPLIES TO
| Article Translations
|

Back to the top
