|
From: Norman V. <nh...@ca...> - 2001-08-31 17:19:04
|
BERNDT, JON S. (JON) (JSC-EX) (LM) writes:
>
> This would require the ability to set the output
>destination to either cout or a file. It would be something like this:
>
>destination_stream << "Altitude: " << "Position->Geth() << endl;
>
>where, depending on the situation, destination_strema refers to either cout
>or my ofstream file. I am not sure if this is possible. Does anyone know
>offhand if this can be done?
Not sure all compilers support this but ....
this works with libstdc++3
#include <fstream.h>
int main()
{
ofstream datafile("jnk");
_IO_ostream_withassign myStream;
if (datafile) {
myStream = datafile;
myStream << "testing datafile" << endl;
myStream = cout;
myStream << "testing cout" << endl;
datafile.close();
}
}
|