简体   繁体   English

如何在C ++中检查输出流是否是std :: cout?

[英]How to check if an output stream is std::cout in C++?

我正在实现输出流运算符<< overload,我需要检查输出流参数os是std :: cout,如果没有,抛出std :: runtime_error - 我该如何检查它?

   friend std::ostream& operator<<(std::ostream& os, const Software &soft)

I question the kind of logic that would lead you to think you have to do this, but if you really want to... 我怀疑会导致你认为你必须这样做的逻辑,但如果你真的想...

if (&os != &std::cout) {
    throw std::runtime_error(/* ... */);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM