我是靠谱客的博主 微笑猎豹,这篇文章主要介绍C++中atof 函数的介绍,现在分享给大家,希望可以做个参考。

一.atof 函数

stdlib.hatof 函数,可用于将 char 字符串转为 float / double 浮点数类型,

语法如下:

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
/* *描述:将一个char类型转为浮点数double * *参数: * [in] str:字符串类型 * *返回值:返回char类型对应的浮点数double */ double atof ( const char * str );

二.atof 函数函数实战

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include "stdafx.h" #include <stdio.h> #include "windows.h" #pragma warning(disable: 4996) int _tmain(int argc, _TCHAR* argv[]) { printf("atof函数计算结果 %f n", atof("13456")); printf("atof函数计算结果 %f n", atof("0")); printf("atof函数计算结果 %f n", atof("789")); printf("atof函数计算结果 %f n", atof("123.123")); printf("atof函数计算结果 %f n", atof("-9")); system("pause"); return 0; }

输出:

atof函数计算结果 13456.000000

atof函数计算结果 0.000000

atof函数计算结果 789.000000

atof函数计算结果 123.123000

atof函数计算结果 -9.000000

请按任意键继续. . .

注意占位符的使用:

  • 浮点是使用 %f
  • 整数是使用 %d
  • char字符是使用 %c
  • char字符串是使用 %s

到此这篇关于C++atof 函数的介绍的文章就介绍到这了,更多相关atof 函数内容请搜索靠谱客以前的文章或继续浏览下面的相关文章希望大家以后多多支持靠谱客!

最后

以上就是微笑猎豹最近收集整理的关于C++中atof 函数的介绍的全部内容,更多相关C++中atof 函数内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(120)

评论列表共有 0 条评论

立即
投稿
返回
顶部