Is there a way in C++ to check if an ostream object is cout or a ofstream object?
Something like:
ostream& output(ostream& out)
{
if (out == cout)
return out;
else
{
out << "something different because its not going to the console" << endl;
return out;
}
}
The reason I want to do this, is that I want to overload the << operator to do two different things depending on what type of stream it is used with.
Is it possible to just overload the << operator twice each time with a different type of stream?
Updated to reflect intention better.
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?