字符串与数字转换方法

本文介绍了在C/C++中字符串转换为数字以及数字转换为字符串的方法,包括CRT函数、sscanf、sprintf以及Windows SDK中的StrToInt等。还讨论了float与double的区别,涉及精度、内存消耗和运算速度。
摘要由CSDN通过智能技术生成

一 字符串转数字

1.CRT函数  (需要的头文件 <stdlib.h> <math.h> <wchar.h>)

  ASCII UNICODE TCHAR VS2005
int atoi _wtoi _tstoi
_ttoi
_atoi_l
_wtoi_l
long atol _wtol _tstoi
_ttoi
_atoi_l
_wtoi_l
__int64 _atoi64 _wtoi64 _tstoi64
_ttoi64
_atoi64_l
_wtoi64_l
float       _atoflt
_atoflt_l
double atof _wtof _tstof
_ttof
_atof_l
_wtof_l
_atodbl
_atodbl_l
long double       _atoldbl
_atoldbl_l

2.使用sscanf  头文件<stdio.h>

sscanf()  从一个字符串中读进与指定格式相符的数据。

原型:

int sscanf( const char *buffer,const char *format [,argument ] ... );
int scanf(const char *format [,argument]... );

其中参数 buffer:输入存储的数据;format:格式控制字符串

sscanf与scanf类似,都是用

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值