字符串转各种数据类型
#include<bits/stdc++.h>
using namespace std;
int main(){
string a="11";
int aa=stoi(a);
cout<<aa<<endl;
string b="111111111111";
long long bb=stoll(b);
cout<<bb<<endl;
string c="11.1";
float cc=stof(c);
cout<<cc<<endl;
string d="11.1111111";
double dd=stod(d);
cout<<dd<<endl;
return 0;
}
各种数据类型转字符串
#include<bits/stdc++.h>
using namespace std;
int main(){
int a=11111;
string aa=to_string(a);
cout<<aa<<endl;
double b=1.1111111;
string bb=to_string(b);
cout<<bb<<endl;
return 0;
}

本文介绍了在C++中如何将字符串转换为整数、长整数、浮点数和双精度浮点数,同时也展示了如何将各种数据类型转换回字符串。通过示例代码,读者可以了解到使用如stoi、stoll、stof、stod和to_string等函数的具体方法。
1778

被折叠的 条评论
为什么被折叠?



