c++ string 转 int longlong float double
隔一段时间不写就忘记函数是什么了,今日记下,以作查询。
#include
using namespace std;
string str;
int aint;
long long alonglong;
float afloat;
double adouble;
int main()
{
str = "1";
aint = stoi(str);
cout<<aint<<endl;
cout<<~(1<<31)<<endl;
str = "214748364700";
alonglong = stoll(str);
cout<<alonglong<<endl;
str = "23.4";
afloat = stof(str);
cout<<afloat<<endl;
str = "6718234.32432";
adouble = stod(str);
cout<<adouble<<endl;
return 0;
}