This is the mail archive of the gcc-help@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]

Re: copying cout and vasprintf


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



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