The information in this article applies to:
SUMMARYThis 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. MORE INFORMATIONThe C function typically used to redirect stdout or stdin is freopen(). To redirect stdout to a file called FILE.TXT, use the following call:
This statement causes all subsequent output, which is typically directed
towards stdout, to go to the file FILE.TXT.
To return stdout to the display (the default stdout), use the following call:
In both of these cases, check the return value of freopen() to make sure
that the redirection actually took place.
Below is a short program to demonstrate the redirection of stdout: Sample Code
This program assumes that stdout is to be redirected toward the console at
the end of the program.
Additional query words:
Keywords : kbCRT kbVC100 kbVC150 kbVC200 kbVC400 kbVC500 kbVC600 |
Last Reviewed: July 1, 1999 © 2000 Microsoft Corporation. All rights reserved. Terms of Use. |