Add time stamp with std::cout
I have the following code which is redirecting my std::cout output to a log file. std::ofstream out("out.txt"); std::streambuf *coutbuf = std::cout.rdbuf(); //save old buf std::cout.rdbuf(out.rdbuf()); //redirect std::cout to out.txt! Now what I want is that whenever a newline is occurring, then the current time stamp will be written to the file. I know I can achive this with: std::cout << getTime() << "printing data" << std::endl; But what I want is that of std::cout taking care of it automatically somehow. Is that possible? I assume, that You want print the TimeStamp, if the first character