By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,531 Members | 2,219 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,531 IT Pros & Developers. It's quick & easy.

Clearing std::stringstream

P: n/a
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
Share this Question
Share on Google+
2 Replies


P: n/a
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

P: n/a
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.