函数的作用是:将str指向的宽字符串的初始部分转换为浮点值。str参数指向可以解释为数字浮点值的字符序列。这些函数在无法识别为数字一部分的第一个字符处停止读取字符串,也就是说,如果第一个字符是除数字以外的任何类型,则函数仅在该字符处终止。该字符可以是字符串末尾的wchar_t null字符。 以“wcs”开头的标准库函数在wchar中声明。C.图书馆。 语法:
null
float wcstof (const wchar_t* str, wchar_t** endptr);Parameters :str : C wide string beginning with the representation of a floating-point number.endptr : Reference to an already allocated object of type wchar_t*, whose value is set by the function to the next character in str after the numerical value.This parameter can also be a null pointer.Return value : Floating point value corresponding to the contents of str on success. If the converted value falls out of range of corresponding return type, range error occurs and is returned.
C
// C code to convert string having // floating point as its content // using wcstof function #include <stdio.h> // header file containing wcstof function #include <wchar.h> int main() { // wide Character array to be parsed wchar_t str[] = L "58.152 9.26" ; // Wide Character array to be parsed wchar_t * pEnd; // float variable to store floating point values float f1, f2; // Parsing the float values to f1 and f2 f1 = wcstof(str, &pEnd); f2 = wcstof(pEnd, NULL); f2 = 2 * f2; // Printing parsed float values of f1 and f2 wprintf(L "%.2f%.2f" , f1, f2); // operation being performed on the values parsed wprintf(L "Value of Pie is %.2f ." , f1 / f2); return 0; } |
输出:
58.1518.52Value of Pie is 3.14 .
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END