在C++中有没有办法检查ostream对象是对象cout还是ofstream对象?
就像是:
ostream& output(ostream& out)
{
if (out == cout)
return out;
else
{
out << "something different because its not going to the console" << endl;
return out;
}
}
我想这样做的原因是,我想重载<<运算符以执行两个不同的操作,具体取决于它使用的流类型.
是否有可能<<每次使用不同类型的流重载操作员两次?
更新以更好地反映意图.