So I have a C++ program, that normally when it executes writes out things to a log file. This is done using an fstream. However, now I want to include functionality to turn the logging off. Essentially, my code looks like this:
bool isLogging;
fstream* logFilePtr;
throughout my code, there are a bunch of statements like:
(*logFilePtr) << " Kernel call time in seconds: " << kTime << endl;
...
Now, if the "isLogging" is true, I don't want these to print. I could just go surround them with a bunch of if statements, but I'd prefer something cleaner than that. I thought there was some way to take a C++ stream and redirect it to point to "nothing" so that when the << operator is used, nothing will print.
Does anyone know how to redirect the stream, or have any other ideas on how to handle this in an elegant way?
Thanks, Colin