1、string转double
#include <iostream> #include <string>
#include <cstdlib> using namespace std;
int main() {
string s; cin >> s;
double n = atof(s.c_str());
cout << n << endl; return 0;
}
2、string转int
#include <iostream>
#include <string>
#include <cstdlib>
using namespace std;
int main() {
string s;
cin >> s;
cout << atoi(s.c_str()) << endl;
return 0;
}
网友评论