C++中atof?函數(shù)的介紹
一.atof 函數(shù)
在 stdlib.h 中 atof 函數(shù),可用于將 char 字符串轉為 float / double 浮點數(shù)類型,
語法如下:
/* *描述:將一個char類型轉為浮點數(shù)double * *參數(shù): * [in] str:字符串類型 * *返回值:返回char類型對應的浮點數(shù)double */ double atof ( const char * str );
二.atof 函數(shù)函數(shù)實戰(zhàn)
#include "stdafx.h"
#include <stdio.h>
#include "windows.h"
#pragma warning(disable: 4996)
int _tmain(int argc, _TCHAR* argv[])
{
printf("atof函數(shù)計算結果 %f \n", atof("13456"));
printf("atof函數(shù)計算結果 %f \n", atof("0"));
printf("atof函數(shù)計算結果 %f \n", atof("789"));
printf("atof函數(shù)計算結果 %f \n", atof("123.123"));
printf("atof函數(shù)計算結果 %f \n", atof("-9"));
system("pause");
return 0;
}
輸出:
atof函數(shù)計算結果 13456.000000
atof函數(shù)計算結果 0.000000
atof函數(shù)計算結果 789.000000
atof函數(shù)計算結果 123.123000
atof函數(shù)計算結果 -9.000000
請按任意鍵繼續(xù). . .
注意占位符的使用:
- 浮點是使用 %f
- 整數(shù)是使用 %d
- char字符是使用 %c
- char字符串是使用 %s
到此這篇關于C++中atof 函數(shù)的介紹的文章就介紹到這了,更多相關atof 函數(shù)內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!
相關文章
C語言雙向鏈表實現(xiàn)根據(jù)使用頻率安排元素位置的功能實例代碼
這篇文章主要介紹了C語言雙向鏈表實現(xiàn)根據(jù)使用頻率安排元素位置的功能實例代碼的相關資料,需要的朋友可以參考下2017-03-03
C語言入門學習之fgets()函數(shù)和fputs()函數(shù)
fgetc() 和 fputc() 函數(shù)每次只能讀寫一個字符,速度較慢,實際開發(fā)中往往是每次讀寫一個字符串或者一個數(shù)據(jù)塊,這樣能明顯提高效率,這篇文章主要給大家介紹了關于C語言入門學習之fgets()函數(shù)和fputs()函數(shù)的相關資料,需要的朋友可以參考下2021-11-11

