#include #include int main () {std :: OFSTREAM logfile ("out.txt"); std :: streambuf * outbuf = std :: cout.rdbuf (logfile.rdbuf ()); STD :: streambuf * errbuf = std :: cerr.rdbuf (logfile.rdbuf ()); // do the actual work of esc: // gui code and evenet loop Would Would Go Here st :: cout << "this 10 Normally Go to cout but goes to the log file / n "; std :: cerr <<" This 10 Normally Go To Cerr But Goes to the log file / n "; logfile <<" this goes to the log file / n "; // end of program std :: cout.rdbuf (Outbuf); std :: cerr.rdbuf (errbuf);} The RDBUF function returns a pointer to the stream buffer managed by the base class Basic_ios. The overload version allows you to replace the flow buffer, the return value is the original stream buffer.