atof 函数 C++中atof 函数的介绍

软件发布|下载排行|最新软件

当前位置:首页IT学院IT技术

atof 函数 C++中atof 函数的介绍

猿说编程   2021-11-27 我要评论
想了解C++中atof 函数的介绍的相关内容吗,猿说编程在本文为您仔细讲解atof 函数的相关知识和一些Code实例,欢迎阅读和指正,我们先划重点:C++中atof 函数,atof 函数,下面大家一起来学习吧。

一.atof 函数

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

语法如下:

/*

*描述:将一个char类型转为浮点数double

*

*参数:

*   [in] str:字符串类型

*

*返回值:返回char类型对应的浮点数double

*/

double atof ( const char * str );

二.atof 函数函数实战

#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

Copyright 2022 版权所有 软件发布 访问手机版

声明:所有软件和文章来自软件开发商或者作者 如有异议 请与本站联系 联系我们