I thought of a small built-in debugging function in C ++:
void inline debug( int debug_level, ostream& out ) {
if ( debug_level <= verbosity ) {
out.flush();
}
else {
ostream tmp;
tmp << out;
}
}
This is an example of how I wanted to use it:
_debug( 7, cout << "Something something" << someint << endl );
However, it doesn’t work as I planned - I wanted it to print a message only if the verbosity level is higher or equal and the debug level is passed to the function, but it seems to print every time, regardless of the debug level, therefore, the data remains in the cout buffer. At the moment, I think this function is not the best idea I have had recently, but still I want to know if there is a way to clear the buffer related to cout, cerr, etc. Is it possible for this function to function correctly?
zbigh source
share