河北大学暑期程序设计训练每日知识分享-day10
每日分享——C++11特性中的to_string
to_string
的的头文件是#include <string>
,to_string
最常⽤的就是把⼀个int
型变量或者double
型变量转化为 string
类型的变量,当然也可以转 double
、float
等类型的变量,这在很多PAT字符串处理的题目中很有用处,以下是示例代码
1 |
|
除此之外,还可以使用stoi
、stod
将字符串string
转化为对应的int
、double
型变量,对于一些字符串处理的题非常有帮助,示例代码如下:
1 |
|
不仅有stoi
、stod
两种,相应的还有:
stof
(string to float)
stold
(string to long double)
stol
(string to long)
stoll
(string to long long)
stoul
(string to unsigned long)
stoull
(string to unsigned long long