作用: 将基本类型的值转换为字符串
基本类型包括int、long long、char等等
使用的时候注意超限问题就好了,特殊地,char类型的转换是转换成它的ASCII值,而不是字符
#includeusing namespace std; int main(){ string s; int a=111111; long long b=222222; char c='a'; s=to_string(a); cout< stoi()函数作用: 将字符串转换为 int 型
使用的时候千万注意细节,不然很容易出现异常的,字符串转回整型别超出整型范围了,还有说一下转换规则:
1、识别的时候左到右,遇到非法符自动停止,非法符号即非数字和前置正负号,如100b345,转换为100,-100-345转换为-100,超出整型会抛出异常#includeusing namespace std; int main(){ string s; s="100b345"; cout< atoi()函数 作用: 和stoi()作用一样,区别是stoi()处理的是string类型,atoi()处理的是const char*类型,而且超过整型范围不会抛出异常
#includeusing namespace std; int main(){ const char *s; s="100b345"; cout< stol()函数 作用: 将字符串转为 long 类型
stoll()函数作用: 将字符串转为 long long 类型
stof()函数作用: 将字符串转为 float 类型
stod()函数作用: 将字符串转为 double 类型
stold()函数作用: 将字符串转为 long double 类型



