如何使用C++中atof函数
生活随笔
收集整理的這篇文章主要介紹了
如何使用C++中atof函数
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
這篇文章主要介紹“如何使用C++中atof函數”,在日常操作中,相信很多人在如何使用C++中atof函數問題上存在疑惑,小編查閱了各式資料,整理出簡單好用的操作方法,希望對大家解答”如何使用C++中atof函數”的疑惑有所幫助!接下來,請跟著小編一起來學習吧!
一.atof 函數
在 stdlib.h 中 atof 函數,可用于將 char 字符串轉為 float / double 浮點數類型,
語法如下:
/* *描述:將一個char類型轉為浮點數double * *參數: *[in]str:字符串類型 * *返回值:返回char類型對應的浮點數double */ doubleatof(constchar*str);
二.atof 函數函數實戰
#include"stdafx.h"
#include<stdio.h>
#include"windows.h"
#pragmawarning(disable:4996)
int_tmain(intargc,_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");
return0;
}
輸出:
atof函數計算結果 13456.000000
atof函數計算結果 0.000000
atof函數計算結果 789.000000
atof函數計算結果 123.123000
atof函數計算結果 -9.000000
請按任意鍵繼續. . .
注意占位符的使用:
浮點是使用 %f
整數是使用 %d
char字符是使用 %c
char字符串是使用 %s
總結
以上是生活随笔為你收集整理的如何使用C++中atof函数的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: vue 微信公众号支付接口_基于vue的
- 下一篇: python中flake8指的是什么