converting an ostream's output to a pure char*

R

ravi

Folks,

I have a heterogenous env. where I developed some C++ code. This code
has the '<<' operator overloaded
to pretty print classes.
This set of classes are instantiated in code which has a constraint on
how to print msgs. (the msgs go to
stdout as well as one or more log files etc. and is controlled by
other factors like brevity of logs etc. Let us
call this function printLog(arg, "format", ...);

What I would ideally like is...
replace 'cout' with 'xout'.
Use xout as always xout << pobj << pobj2 << endl;
Some how get access (readonly is fine) to the formatted string
const char* p = xout.getString() (???)
printLog (args, "%s", p);

Question is how to extract the formatted string from a stream object.

Any help appreciated.

-ravi
 
A

AnonMail2005

Folks,

I have a heterogenous env. where I developed some C++ code. This code
has the '<<' operator overloaded
to pretty print classes.
This set of classes are instantiated in code which has a constraint on
how to print msgs. (the msgs go to
stdout as well as one or more log files etc. and is controlled by
other factors like brevity of logs etc. Let us
call this function printLog(arg, "format", ...);

What I would ideally like is...
replace 'cout' with 'xout'.
Use xout as always xout << pobj << pobj2 << endl;
Some how get access (readonly is fine) to the formatted string
const char* p = xout.getString() (???)
printLog (args, "%s", p);

Question is how to extract the formatted string from a stream object.

Any help appreciated.

-ravi

Your xout looks like alot like a std::eek:stringstream (or some object
that contains one). You can get a std::string from that, as well as a
char *. Then you can output it to as many places as you want - cout,
log files, etc.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,577
Members
45,054
Latest member
LucyCarper

Latest Threads

Top