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
Post a Comment