how to clear up the std::stringstream?

K

kathy

I am trying to convert integer to std::string by using:

int m,n;
std::string s1,s2;
std::stringstream sStream;
sStream << m;
s1 = sStream.str();

????? how to clear up sStream ???

sStream << n;
s2 = sStream.str();
 
J

Jeff Flinn

kathy said:
I am trying to convert integer to std::string by using:

int m,n;
std::string s1,s2;
std::stringstream sStream;
sStream << m;
s1 = sStream.str();

????? how to clear up sStream ???


sStream.str("");
sStream << n;
s2 = sStream.str();

See http://www.boost.org/libs/conversion/lexical_cast.htm for the
lexical_cast library which lets you:

std::string s1( boost::lexical_cast<std::string>( m ) );
std::string s2( boost::lexical_cast<std::string>( n ) );


Jeff
 

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

Similar Threads


Members online

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top