atof函数 C++用法

atof函数 C++用法atof 函数原型 doubleatof constchar string ASCIItofloat 作用 将字符串转为 double 类型 nbsp 对于以上函数 若字符串无法转化为合法的数值类型 函数将返回 0 使用范例 来自 MSDN 1 include nbsp stdlib h2 include nbsp stdio h34voi

atof函数

原型:double atof( const char *string );

ASCII to float

作用:将字符串转为double类型

 

对于以上函数,若字符串无法转化为合法的数值类型,函数将返回0 。

使用范例(来自MSDN):

复制代码

atof函数 C++用法
1atof函数 C++用法#include <stdlib.h>

2atof函数 C++用法#include <stdio.h>

3atof函数 C++用法

4atof函数 C++用法void main( void )

5atof函数 C++用法{


6atof函数 C++用法   char *s; double x; int i; long l;

7atof函数 C++用法

8atof函数 C++用法    printf(  testing atoi,atof,atol function :\n ) ;

9atof函数 C++用法    s =    -2309.12E-15;    /* Test of atof */

10atof函数 C++用法    x = atof( s );

11atof函数 C++用法    printf( atof test: ASCII string: %s\tfloat:   %e\n, s, x );

12atof函数 C++用法

13atof函数 C++用法    s = 7.8912654773d210;  /* Test of atof */

14atof函数 C++用法    x = atof( s );

15atof函数 C++用法    printf( atof test: ASCII string: %s\tfloat:   %e\n, s, x );

16atof函数 C++用法

17atof函数 C++用法    s =    -9885 pigs;      /* Test of atoi */

18atof函数 C++用法    i = atoi( s );

19atof函数 C++用法    printf( atoi test: ASCII string: %s\t\tinteger: %d\n, s, i );

20atof函数 C++用法

21atof函数 C++用法    s = 98854 dollars;     /* Test of atol */

22atof函数 C++用法    l = atol( s );

23atof函数 C++用法    printf( atol test: ASCII string: %s\t\tlong: %ld\n, s, l );

24atof函数 C++用法}

25atof函数 C++用法

复制代码

输出:

atof test: ASCII string:   -2309.12E-15 float: -2.e-012

atof test: ASCII string: 7.d210 float: 7.e+210

atoi test: ASCII string:   -9885 pigs    integer: -9885

atol test: ASCII string: 98854 dollars    long: 98854



版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/212305.html原文链接:https://javaforall.net

(0)
上一篇 2026年3月18日 下午8:21
下一篇 2026年3月18日 下午8:21


相关推荐

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号