如何从源代码中禁用std :: clog日志记录?

Yeo*_*Yeo 7 c++ c++11

在开发代码时,我有许多控制台日志记录(std::clog)和一些控制台输出(std::cout).但现在,我想在线提交我的源代码,我想禁用所有控制台日志(clog)但保持控制台输出(cout)

我可以肯定地评论我的所有内容//std::clog,但有没有更好的方法来禁用我的源文件中的所有日志记录?

Wik*_*ang 7

您可以重定向clog,创建自己的ofstream并使用rdbuf函数.

std::ofstream nullstream;
std::clog.rdbuf(nullstream.rdbuf());
Run Code Online (Sandbox Code Playgroud)