在我的场景中,当有些方法产生调试输出时,我有许多行代码与各种#define控制.我想打个电话:
cout.off(); driverForAffectA(); driverForAffectB(); cout.on(); printSpecializedDebug(); exit(0);
streambuf *old = cout.rdbuf(); cout.rdbuf(0); cout << "Hidden text!\n"; cout.rdbuf(old); cout << "Visible text!\n";
编辑:
感谢John Flatness的评论,您可以缩短代码:
streambuf *old = cout.rdbuf(0); cout << "Hidden text!\n"; cout.rdbuf(old); cout << "Visible text!\n";