c++ - Programmatically Ignore Cout -


does know if there trick toggle cout << functions not print out visible output? trying hack code written me , other people put demo. rather not redirect output file , solution had measure of compatibility between windows , linux.

in scenario have many many lines of code with various #defines controlling when methods produce debug output. want call like:

cout.off(); driverforaffecta(); driverforaffectb(); cout.on(); printspecializeddebug(); exit(0); 

you can change cout's stream buffer.

streambuf *old = cout.rdbuf(); cout.rdbuf(0); cout << "hidden text!\n"; cout.rdbuf(old); cout << "visible text!\n"; 

edit:

thanks john flatness' comment can shorten code bit:

streambuf *old = cout.rdbuf(0); cout << "hidden text!\n"; cout.rdbuf(old); cout << "visible text!\n"; 

Comments

Popular posts from this blog

Python __call__ special method practical example -

arrays - jQuery - Retrieve values from HTML elements and return their sum -