问题描述
我经常使用 cout
在我的代码中的许多不同的地方进行调试,然后我感到沮丧,并手动评论所有的。
有没有办法在运行时抑制cout输出?
更重要的是,以抑制所有 cout
输出,但我仍然想在终端中看到1个特定输出(我们说程序的最终输出)。
可以使用其他方式打印到终端来显示程序输出,然后当抑制cout仍然看到打印使用
不要使用 cout
为调试目的,但定义一个不同的对象(或函数或宏)调用它,那么你可以在一个地方禁用该函数或宏。
I often use cout
for debugging purpose in many different places in my code, and then I get frustrated and comment all of them manually.
Is there a way to suppress cout output in the runtime?
And more importantly, let's say I want to suppress all cout
outputs, but I still want to see 1 specific output (let's say the final output of the program) in the terminal.
Is it possible to use an ""other way"" of printing to the terminal for showing the program output, and then when suppressing cout still see things that are printed using this ""other way""?
Don't use cout
for debugging purposes, but define a different object (or function, or macro) that calls through to it, then you can disable that function or macro in one single place.
这篇关于如何在运行时禁用cout输出?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!