这个 wcstod() 函数将宽字符串转换为 双重的 。此函数将宽字符串的内容解释为浮点数。如果 尾串 不是空指针,该函数还设置 尾串 指向数字后的第一个字符。
null
语法:
double wcstod( const wchar_t* str, wchar_t** str_end )
参数: 该函数接受两个强制参数,如下所述:
- 字符串: 指定以浮点数表示形式开头的字符串
- 结束字符串: 指定指向宽字符的指针
返回值: 该函数返回两个值,如下所示:
- 如果成功,函数将转换后的浮点数作为double类型的值返回。
- 如果无法执行有效的转换,则返回0.0。
- 如果正确的值超出了类型的可表示值的范围,则会返回一个正或负的大值,并将errno设置为ERANGE。
- 如果正确的值会导致下溢,该函数将返回一个值,其大小不大于最小的规范化正数(在这种情况下,一些库实现还可能将errno设置为ERANGE)。
以下程序说明了上述功能: 项目1:
// C++ program to illustrate // wcstod() function #include <bits/stdc++.h> using namespace std; int main() { // initialize the wide string // beginning with the floating point number wchar_t string[] = L "95.6Geek" ; // Pointer to a pointer to a wide character wchar_t * endString; // Convert wide string to double double value = wcstod(string, &endString); // print the string, starting double value // and its endstring wcout << L "String -> " << string << "" ; wcout << L "Double value -> " << value << "" ; wcout << L "End String is : " << endString << "" ; return 0; } |
输出:
String -> 95.6Geek Double value -> 95.6 End String is : Geek
项目2:
// C++ program to illustrate // wcstod() function // with no endString characters #include <bits/stdc++.h> using namespace std; int main() { // initialize the wide string // beginning with the floating point number wchar_t string[] = L "10.6464" ; // Pointer to a pointer to a wide character wchar_t * endString; // Convert wide string to double double value = wcstod(string, &endString); // print the string, starting double value // and its endstring wcout << L "String -> " << string << "" ; wcout << L "Double value -> " << value << "" ; wcout << L "End String is : " << endString << "" ; return 0; } |
输出:
String -> 10.6464 Double value -> 10.6464 End String is :
方案3:
// C++ program to illustrate // wcstod() function // with whitespace present at the beginning #include <bits/stdc++.h> using namespace std; int main() { // initialize the wide string // beginning with the floating point number wchar_t string[] = L " 99.999Geek" ; // Pointer to a pointer to a wide character wchar_t * endString; // Convert wide string to double double value = wcstod(string, &endString); // print the string, starting double value // and its endstring wcout << L "String -> " << string << "" ; wcout << L "Double value -> " << value << "" ; wcout << L "End String is : " << endString << "" ; return 0; } |
输出:
String -> 99.999Geek Double value -> 99.999 End String is : Geek
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END