473,326 Members | 2,148 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

stringstream problem

Hi all,

I am trying to use stringstream to assemble a text message from a set
of user-defined objects that have the insertion operator overloaded.
It seems to be putting them into the stringstream fine....however, I
need to assemble it in "parts" (eg a prefix, a header, a body, a
trailer and a checksum), and would like to reuse the stringstream to
format that various parts....but I ahve not found a successful way to
"empty" the stringstream object after one set of insertion operations.
The code needs to work on both VC++ 6 and UNIX (Solaris) patforms. I
have tried something like this:

stringstream ssMsg;
string strHeader;
string strBody;

ssMsg << m_Header; // format the header object as a string
strHeader = ssMsg.str();

ssMsg.flush() // <--- one attempt to "empty" the stringstream....didnt
work
// also tried ssMsg.str("") which seemed to 'work' in
VC++ 6

ssMsg << m_Body; // <-- on UNIX this now has header & body
strHeader = ssMSg.str(); // <-- so, this now has header and body when
I want only the body...

....
etc

would using the string extraction operator help?
eg

ssMsg >> strHeader;

The stream MAY have embedded spaces and/or newlines...

Comments on approach also welcome....

Thanks in advance.

Bill
Jul 19 '05 #1
2 5831
> ....but I ahve not found a successful way to
"empty" the stringstream object after one set of insertion operations.

ssMsg.flush() // <--- one attempt to "empty" the stringstream...
// also tried ssMsg.str("") which seemed to 'work' in VC++ 6


ssMsg.str (""); // this way is correct.

Regards,
Buster.
Jul 19 '05 #2

"Buster" <no***@nowhere.com> wrote in message
news:bk**********@newsg2.svr.pol.co.uk...
....but I ahve not found a successful way to
"empty" the stringstream object after one set of insertion operations.

ssMsg.flush() // <--- one attempt to "empty" the stringstream...
// also tried ssMsg.str("") which seemed to 'work' in VC++ 6
ssMsg.str (""); // this way is correct.


or

ssMsg.str(string());

Regards,
Buster.


BR,
Peter Kragh
Jul 19 '05 #3

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

Similar topics

4
by: David Johnstone | last post by:
Hi Group, I am using gcc 3.2.2 on linux 2.4.19-4GB (SuSe 8.2). I have a situation where I need to tie an ostringstream to an istringstream so I can write to one and read back what I wrote...
3
by: Mike Chirico | last post by:
Sorry about the newbie question. What's the best way to convert numbers to strings in C++. The following works, but is it better than using the sprintf() "old C" way of converting? #include...
5
by: cherico | last post by:
I'd like to read stings from cin and put them in stringstream. I use a string object as an intermediate "container" to store data from cin and then put them in stringstream. stringstream ss ;...
3
by: David Olsson | last post by:
Hello! I have a little problem with one of the get methods of the stringstream class. Consider the code: #include <iostream> #include <sstream> #include <string> using namespace std;
2
by: avidamani | last post by:
Hi, I have a c++ application compiled using Compaq C++ V6.5-014 for Compaq Tru64 UNIX V5.1A (Rev. 1885) Compiler Driver V6.5-014 (cxx) cxx Driver The problem is that the application is...
3
by: mlm | last post by:
Hi, I believe that it should not be legal to create a vector (and array) of stringstream since the copy constructor and assignment operators are declared private. However, I don't understand...
10
by: vigacmoe | last post by:
I was trying to cast some strings to integers with stringstream, then this strange problem poped up. Here is my test code: stringstream conv; string from; int to; from = "1"; conv << from;
0
by: ziyanjoe | last post by:
Hi! I am writing a program for the robot that runs as a daemon on a linux machine. Since debug output cannot be seen on stdout, I want to create an iostream to handle all the output messages....
4
by: mthread | last post by:
Hi, I am using a string variable in which I do lot of appending. The only difficulty I am facing as of now is appending a integer/float value to this variable. Although I can accomplish this task...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.