str
x
int x=atoi(str)
int x = atoi(str.c_str());
12345678910
#include <sstream> // or // #include <sstream.h> // ... std::stringstream ss(str); // or // stringstream ss(str); int x; ss >> x;
1234567891011121314
#include<iostream> #include<sstream> using namespace std; int main () { string s; stringstream ss; int n; cin>>s; ss<<s; ss>>n; cout<<n; return 0; }
123456789
#include <string> #include <sstream> int strToNum(string str) { istringstream ss(str); int n; ss >> n; return n; }
123456
string numToStr(int n) { ostringstream ss; ss << n; return ss.str(); }
12345
template <typename Number> std::string number_to_string(Number n) { return dynamic_cast<std::stringstream *> (&(std::stringstream() << n))->str(); }