* copying cout and vasprintf
@ 2001-12-10 13:53 Eddy Ilg
2001-12-11 5:43 ` John Love-Jensen
0 siblings, 1 reply; 2+ messages in thread
From: Eddy Ilg @ 2001-12-10 13:53 UTC (permalink / raw)
To: gcc-help
Hi gcc gurus,
I want to output log information from my program to either cout or a file. I want it somewhat like this;
ostream log_stream;
if (output_stout) {
log_stream=cout;
} else if (output_file) {
log_stream=ofstream(log_file);
}
By just trying log_stream=cout; I get this though:
/usr/include/g++/streambuf.h:128: `ios::ios(const ios &)' is private
log.cc:16: within this context
How can I do something like the above?
Another question: I want to use vasprintf(). This does not seem to be ANSI. I tried the following:
#define __USE_GNU
#include <stdio.h>
#include <stdlib.h>
void foo()
{
vasprintf(..)
}
g++ tells me that vasprintf is not defined. Do I have to use another preprocessor define that __USE_GNU?
Thanks a lot
Eddy
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: copying cout and vasprintf
2001-12-10 13:53 copying cout and vasprintf Eddy Ilg
@ 2001-12-11 5:43 ` John Love-Jensen
0 siblings, 0 replies; 2+ messages in thread
From: John Love-Jensen @ 2001-12-11 5:43 UTC (permalink / raw)
To: gcc-help, Eddy Ilg
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
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2001-12-11 13:43 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-12-10 13:53 copying cout and vasprintf Eddy Ilg
2001-12-11 5:43 ` John Love-Jensen
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).