c++的类型转换

1.int转string,函数to_string()

x=10;
string m=to_string(x);

经测试gcc v5.4.0版本不支持,版本v7.5.0支持。判断版本号命令:g++ -v

同样适用于double,float

2.string转int,函数atoi()

string i="100";
cout << atoi(i.c_str())+1 << endl;

返回101

 

posted on 2022-09-01 10:50  RicLiu  阅读(18)  评论(0编辑  收藏  举报