如何在运行时禁用cout输出? [英] How to disable cout output in the runtime?

查看:902
本文介绍了如何在运行时禁用cout输出?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我经常使用 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输出?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆