字符串转换为double的函数strtod

来自MSDN的函数原型:

原型一:double strtod(const char *nptr,  char **endptr);
原型二:double _strtod_l(const char *nptr, char **endptr, _locale_t locale);
原型三:double wcstod(const wchar_t *nptr, wchar_t **endptr);
原型四:double wcstod_l(const wchar_t *nptr, wchar_t **endptr,  _locale_t locale);
其中:

           nptr --- 需要转换的字符串(Null-terminated string to convert.)

       endptr --- 存储扫描结束位置的指针(Pointer to character that stops scan.)

        locale  --- 区域代码(The locale to use.)

这个函数扫描字符串中的数字,直到第一个非字符串结束,并将位置存到指针endptr中。

 

举例说明:

   WCHAR   *string, *stopstring;
   double x;

   string = L"3.1415926This stopped it";
   x = strtod( string, &stopstring );
   printf( "string = %s/n", string );
   printf("   strtod = %f/n", x );
   printf("   Stopped scan at: %s/n/n", stopstring );

输出结果:

string = 3.1415926This stopped it
strtod = 3.141593
Stopped scan at: This stopped it

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值