473,471 Members | 4,616 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

converting an ostream's output to a pure char*

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
Jul 17 '08 #1
1 2403
On Jul 17, 1:44*pm, ravi <ravi.ck.ku...@gmail.comwrote:
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::ostringstream (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.
Jul 17 '08 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: joesoap | last post by:
Hi can anybody please tell me what is wrong with my ostream operator??? this is the output i get using the 3 attached files. this is the output after i run assignment2 -joesoap #include...
2
by: Trevor | last post by:
Hello, Please bear with me, I am trying to learn C++. I am implementing some error/debug functions which format a message and output it to a C++ stream. I would like to design it using one low...
9
by: Ingo Nolden | last post by:
Hi there, I am writing c++ for some months now. I think I know the language now, but not yet all the tricky things of stl. For a kernel which is not using mfc I am writing a serialization. For...
0
by: Steven T. Hatton | last post by:
I tried to create my own manipulator that would both set the width of the subsequent output field, and cast an unsigned char to unsigned in. I came up with the following rather ugly hack. Notice...
4
by: Brett | last post by:
Hi, I'm having trouble converting an old project to visual studio C++ .net v7.1.3088 I've updated one of the header files to use #include <iostream>, and used the std namspace. After...
4
by: Rock | last post by:
I'm in the process of writing this program for complex numbers and I use DevC++. My professor on the other hand compiles on Borland 5.5. So I ocasionally save and run my work on Borland to see if...
13
by: Peteroid | last post by:
These don't work (I'm using VS C++.NET 2005 Express with clr:/pure syntax): ostream& operator <<( ostream& output, String^ str ) { output << str ; //compile error return output ; } ...
2
by: waitan | last post by:
#include <algorithm> #include <iostream> #include <fstream> #include <string> #include <vector> #include <sstream> #include <iterator> #include <iomanip> using namespace std;
6
by: silversurfer2025 | last post by:
Hello, I am currently trying to derive a class from ostream (which is giving output to my GUI), such that I can give my methods either std::cout or my own outputstream-class to be used as output...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.