Tuesday, June 7, 2016

[C++] Re-direction cout to log file

#include #include using namespace std; ofstream _log_file_; ... ... ... _log_file_.open("log.txt"); if( !_log_file_.is_open() ) { // Error handling } _log_file_.copyfmt( cout ); cout.rdbuf( _log_file_.rdbuf() ); // From now on, text of cout re-direct to file : log.txt ... ... ... _log_file_.close();

No comments: