c语言atof函数_atof()函数与C ++中的示例
c语言atof函数
C ++ atof()函数 (C++ atof() function)
atof() function is a library function of cstdlib header. It is used to convert the given string value to the double value. It accepts a string containing a floating-point number and returns its double value.
atof()函数是cstdlib标头的库函数。 它用于将给定的字符串值转换为双精度值。 它接受包含浮点数的字符串,并返回其双精度值。
Syntax of atof() function:
atof()函数的语法:
C++11:
C ++ 11:
double atof (const char* str);
Parameter(s):
参数:
str – represents a string containing a floating-point number.
str –表示包含浮点数的字符串。
Return value:
返回值:
The return type of this function is double, it returns the double converted value.
该函数的返回类型为double ,它返回double转换后的值。
Example:
例:
Input:
str = "123.456";
Function call:
atof(str);
Output:
123.456
C ++代码演示atof()函数的示例 (C++ code to demonstrate the example of atof() function)
// C++ code to demonstrate the example of
// atof() function
#include <iostream>
#include <cstdlib>
#include <string.h>
using namespace std;
// main() section
int main()
{
char str[50];
strcpy(str, "123.456");
cout << "atof(\"" << str << "\"): " << atof(str) << endl;
strcpy(str, "-123.456");
cout << "atof(\"" << str << "\"): " << atof(str) << endl;
strcpy(str, "0.123456");
cout << "atof(\"" << str << "\"): " << atof(str) << endl;
strcpy(str, "-0.123456");
cout << "atof(\"" << str << "\"): " << atof(str) << endl;
strcpy(str, "12345678.123456");
cout << "atof(\"" << str << "\"): " << atof(str) << endl;
strcpy(str, "-12345678.123456");
cout << "atof(\"" << str << "\"): " << atof(str) << endl;
return 0;
}
Output
输出量
atof("123.456"): 123.456
atof("-123.456"): -123.456
atof("0.123456"): 0.123456
atof("-0.123456"): -0.123456
atof("12345678.123456"): 1.23457e+07
atof("-12345678.123456"): -1.23457e+07
Reference: C++ atof() function
参考: C ++ atof()函数
翻译自: https://www.includehelp.com/cpp-tutorial/atof-function-with-example.aspx
c语言atof函数
还没有评论,来说两句吧...