Check if ostream object is cout or ofstream, c++

后端 未结 4 1896
北恋
北恋 2020-12-06 11:26

Is there a way in C++ to check if an ostream object is cout or a ofstream object?

Something like:

ostream& ou         


        
4条回答
  •  情书的邮戳
    2020-12-06 11:48

    It's possible by checking the stream's 'identity': if ( &out == &cout ) ....

    However, I'm in doubt on the usefullness of this test. If your function can handle any output stream, why bother about what stream it is using?

提交回复
热议问题