This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Redirecting I/O


This isn't a compiler question and I apologize for that. I'm having a devil of a time getting an answer to my issues on the C/C++ forums I'm using and, sigh, perhaps someone can direct me to a forum where the questions can be better addressed.

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

int main(..){
  out = cout;    // won't work
}

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.

Anyone know how to solve these two issues?


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]