you can just use a wrapper class to do this, something like this
#include <iostream> #include <fstream> ... class streamoutput { std::ofstream fileoutput; public: streamoutput(char*filename){ fileoutput.open(filename); } ~streamoutput(){ fileoutput.close(); } template<class TOut> streamoutput& operator <<(const TOut& data) { fileoutput << data; std::cout << data; return this; } }; extern streamoutput cout("logfile.log");
declare cout this way and just change all your #include <iostream> to include this shell (remeber cout is an external variable, so you need to specify it in one of your source codes too).
Ali1S232
source share