12345678910111213141516171819
/*Convert string into int using stringstream */ #include <iostream> #include <string> #include "console.h" #include <sstream> using namespace std; int main() { string text; cout << " String2Int : " ; cin >> text; int Number; if ( !(istringstream(text) >> Number) ) { //give the value to Number(int) Number = 0; //Set Number=0 if fail cout << " Failed to convert ! "<< endl; }else{ cout << "Conversion Complete ! "<<endl; } }
123456
std::string ToString( int n ) { std::stringstream s; s << n; return s.str(); }
string = boost::lexical_cast<std::string>(n);