For those of you interested:
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;
}
Everything sent to cout will be sent to the file identified in the #define. Any other output will be unaffected.
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.