This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: copying cout and vasprintf
- From: "John Love-Jensen" <eljay at adobe dot com>
- To: <gcc-help at gcc dot gnu dot org>, "Eddy Ilg" <eddy at fericom dot net>
- Date: Tue, 11 Dec 2001 07:35:24 -0600
- Subject: Re: copying cout and vasprintf
- References: <20011210225306.A22974@fericom.net>
Hi Eddy,
Use:
ostream* log_stream;
bool log_stream_delete = false; // Ownership and management.
if(output_stout) {
log_stream = &cout;
} else if(output_file) {
log_stream_delete = true;
log_stream = new ofstream(log_file);
}
*log_stream << "Hello world." << endl; // Note the "*log_stream" syntax.
if(log_stream_delete) {
ostream* t = log_stream;
log_stream = &cout; // Just in case we forget.
delete t;
log_stream_delete = false;
}
--Eljay