STL中string与其余类型之间的转换方式

本文聚焦于C++编程,介绍了string类型与其他类型之间的转换接口,包括string转int、long等多种数值类型,以及其他类型转string和wstring,所有接口均声明在string头文件中。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

本文介绍了string类型与其他类型之间的转换接口,所有的接口均声明在string头文件当中。

#include <string>

1、string 转换为 int

stoi("1234");  // 1234

2、string 转换为 long

stol("10000000"); // 10000000

3、string 转换为 unsigned long

stoul("10000000"); // 10000000

4、string 转换为 long long

stoll("10000000"); // 10000000

5、string 转换为 unsigned long long

stoull("10000000"); // 10000000

6、string 转换为 float

stof("10.123"); // 10.123

7、string 转换为 double

stod("10.123456"); // 10.123456

8、string 转换为 long double

stold("10.123456"); // 10.123456

9、val (其他类型)转换为 string

to_string(12345); // "12345"

10、val (其他类型)转换为 wstring

to_wstring(12345); // "12345"

谢谢阅读

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值