Is there any mechanism for trapping stdout to a file under Win98? A language feature or something I could do to the console?
Printable View
Is there any mechanism for trapping stdout to a file under Win98? A language feature or something I could do to the console?
n/m found it.
For those of you interested:
Everything sent to cout will be sent to the file identified in the #define. Any other output will be unaffected.Code:/*
Info and includes
*/
#define STDOUT_TO_FILE "outfile.txt"
/*
declarations and anything else
*/
int main () {
#ifdef STDOUT_TO_FILE
FILE* newoutput = freopen(STDOUT_TO_FILE, "w", stdout );
if (!newoutput) {
cerr << "Failed to redirect stdout";
return (1);
}
#endif
/*
body of main()
*/
#ifdef STDOUT_TO_FILE
fclose(newoutput);
#endif
return 0;
}
Comment out the define and all is as it was, the other stuff isn't even processed.
This would probably not work with things like conio.h and anything that writes directly to the video memory.
Dunno if this is faqworthy or not, but definitely useful information.