C++中atof?函數(shù)的介紹
一.atof 函數(shù)
在 stdlib.h
中 atof
函數(shù),可用于將 char
字符串轉(zhuǎn)為 float / double
浮點(diǎn)數(shù)類型,
語法如下:
/* *描述:將一個char類型轉(zhuǎn)為浮點(diǎn)數(shù)double * *參數(shù): * [in] str:字符串類型 * *返回值:返回char類型對應(yīng)的浮點(diǎn)數(shù)double */ double atof ( const char * str );
二.atof 函數(shù)函數(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ù)計(jì)算結(jié)果 %f \n", atof("13456")); printf("atof函數(shù)計(jì)算結(jié)果 %f \n", atof("0")); printf("atof函數(shù)計(jì)算結(jié)果 %f \n", atof("789")); printf("atof函數(shù)計(jì)算結(jié)果 %f \n", atof("123.123")); printf("atof函數(shù)計(jì)算結(jié)果 %f \n", atof("-9")); system("pause"); return 0; }
輸出:
atof函數(shù)計(jì)算結(jié)果 13456.000000
atof函數(shù)計(jì)算結(jié)果 0.000000
atof函數(shù)計(jì)算結(jié)果 789.000000
atof函數(shù)計(jì)算結(jié)果 123.123000
atof函數(shù)計(jì)算結(jié)果 -9.000000
請按任意鍵繼續(xù). . .
注意占位符的使用:
- 浮點(diǎn)是使用 %f
- 整數(shù)是使用 %d
- char字符是使用 %c
- char字符串是使用 %s
到此這篇關(guān)于C++
中atof
函數(shù)的介紹的文章就介紹到這了,更多相關(guān)atof 函數(shù)內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
C++ BloomFilter布隆過濾器應(yīng)用及概念詳解
布隆過濾器是由布?。˙urton Howard Bloom)在1970年提出的 一種緊湊型的、比較巧妙的概率型數(shù)據(jù)結(jié)構(gòu),特點(diǎn)是高效地插入和查詢,可以用來告訴你 “某樣?xùn)|西一定不存在或者可能存在”,它是用多個哈希函數(shù),將一個數(shù)據(jù)映射到位圖結(jié)構(gòu)中2023-03-03Visual Studio Code 配置C、C++環(huán)境/編譯并運(yùn)行的流程分析
這篇文章主要介紹了Visual Studio Code 配置C、C++環(huán)境/編譯并運(yùn)行的流程分析,本文通過圖文并茂的形式給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下2020-05-05北郵計(jì)算機(jī)考研復(fù)試題的C語言解答精選
這篇文章主要介紹了北郵計(jì)算機(jī)考研復(fù)試題目的C語言解答精選,選自2012年的一些基礎(chǔ)的上機(jī)題目,需要的朋友可以參考下2015-08-08