This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Redirecting I/O
- From: Arthur Schwarz <aschwarz1309 at verizon dot net>
- To: gcc at gcc dot gnu dot org
- Date: Fri, 10 Apr 2009 10:57:37 -0700 (PDT)
- Subject: 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?