I've been using stringstream
to convert Integer
to String
, but then I realized same operation can be done with ostringstream
.
When I use .str()
what is the difference between them? Also, is there more efficient way to convert integers to strings?
Sample code:
//using ostringstream
ostringstream s1;
int i=100;
s1<<i;
string str_i=s1.str();
cout<<str_i<<endl;
//using stringstream
stringstream s2;
int i2=100;
s2<<i2;
string str_i2=s2.str();
cout<<str_i2<<endl;