469,592 Members | 1,900 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,592 developers. It's quick & easy.

Clearing std::stringstream

I am using std::stringstream to format a string. How can I clear the
stringstream variable I am using to "re use" the same variable?

Eg:

Using std::string

std::string buffer;

buffer = "value1" + " : " + "value2";
buffer = "value3" + " : " + "value4";

Gives values of
value1 : value2
value3 : value4

The = operator for std::string overwrites the preivous contents of the
string, but I have been unable to locate a similar thing for
std:stringstream

using std::stringstream

std::stringstream buffer;

buffer << "value1" << " : " << "value2";
buffer << "value3" << " : " << "value4";

Gives values of
value1 : value2
value1 : value2value3 : value4

Which is not the desired result. How should I go about clearing the
buffer of a std::stringstream?

Thanks in advance

Jul 19 '05 #1
2 7173
Woodster wrote:
....

using std::stringstream

std::stringstream buffer;

buffer << "value1" << " : " << "value2";
buffer.str( "" ); // set the contents to the empty string.
buffer << "value3" << " : " << "value4";

Gives values of
value1 : value2
value1 : value2value3 : value4

Which is not the desired result. How should I go about clearing the
buffer of a std::stringstream?


use the .str( string ) method ... it should be an FAQ.

Jul 19 '05 #2
I'm not sure, but you can try

buffer.flush();

Catalin

"Woodster" <mi****@127.0.0.1> wrote in message
news:MP************************@news.westnet.com.a u...
I am using std::stringstream to format a string. How can I clear the
stringstream variable I am using to "re use" the same variable?

Eg:

Using std::string

std::string buffer;

buffer = "value1" + " : " + "value2";
buffer = "value3" + " : " + "value4";

Gives values of
value1 : value2
value3 : value4

The = operator for std::string overwrites the preivous contents of the
string, but I have been unable to locate a similar thing for
std:stringstream

using std::stringstream

std::stringstream buffer;

buffer << "value1" << " : " << "value2";
buffer << "value3" << " : " << "value4";

Gives values of
value1 : value2
value1 : value2value3 : value4

Which is not the desired result. How should I go about clearing the
buffer of a std::stringstream?

Thanks in advance

Jul 19 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by Giampiero Gabbiani | last post: by
1 post views Thread by KidLogik | last post: by
5 posts views Thread by Marcin Kalicinski | last post: by
1 post views Thread by magix | last post: by
2 posts views Thread by akitoto | last post: by
7 posts views Thread by Grey Alien | last post: by
3 posts views Thread by Rune Allnor | last post: by
reply views Thread by suresh191 | last post: by
4 posts views Thread by guiromero | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.