Monday, May 28, 2012

Convert int to string in C++

STRINGSTREAM can be used  in C++ to convert int to string


string int2str (int n) {
stringstream ss;
ss << n;
return ss.str();
}

How to convert string to integer in C++

With the help of stringstream a string can be converted into integer
 

int str2int (const string &str) {
stringstream ss(str);
int n;
ss >> n;
return n;
}