One can remove all calls to printf() using #define printf. What if I have a lot of debug prints like std::cout << x << endl; ? How can I quickly switch off cout << statements in a single file using preprocessor?
One can remove all calls to printf() using #define printf . What if I
Share
NullStream can be a good solution if you are looking for something quick that removes debug statements. However I would recommend creating your own class for debugging, that can be expanded as needed when more debug functionality is required:
This is a simple setup that can do what you want initially, plus it has the added benefit of letting you add functionality such as debug levels etc..
Update:
Now since manipulators are implemented as functions, if you want to accept manipulators as well (endl) you can add:
And for all manipulator types (So that you don’t have to overload for all manipulator types):
Be careful with this last one, because that will also accept regular functions pointers.