(This question probably should be on gcc-help instead of this list.)

> I'm trying to redirect I/O in my C++ application and am having some
> difficulty. I am trying to use cout or a file for output based on some
> condition. cout is an ostream object and file is an ofstream object.
> The types are incompatible, as in:
>
> bool condition;
> ofstream x;
> ofstream out = (condition)?cout: x;   // won't work because of cout

Try:

ostream& out = condition ? cout : x;

> In addition I would like to redirect an ofstream object to be the same as
> out, as in;
>
> void fn() { object = out; } // won't work because '=' is private.

Again, try declaring object as "ostream&".

-cary

Reply via email to