📅  最后修改于: 2020-09-25 10:04:49             🧑  作者: Mango
该wcstod() 函数还设置一个指针指向第一个宽字符 ,如果有任何的宽字符串的最后一个有效字符之后,否则指针设置为null。
它在
double wcstod( const wchar_t* str, wchar_t** str_end );
wcstod() 函数将宽字符串和指向宽字符的指针作为其参数,将宽字符串的内容解释为浮点数并返回双精度值。
wcstod() 函数返回:
如果转换后的值超出范围,则发生范围错误,并返回正或负的HUGE_VAL 。
#include
#include
#include
using namespace std;
int main()
{
setlocale(LC_ALL, "en_US.UTF-8");
wchar_t str[] = L"83.201xz\u0496\u0687";
wchar_t *end;
double value;
value = wcstod(str,&end);
wcout << L"Wide String = " << str << endl;
wcout << L"Double value = " << value << endl;
wcout << L"End String = " << end << endl;
return 0;
}
运行该程序时,输出为:
Wide String = 83.201xzҖڇ
Double value = 83.201
End String = xzҖڇ
#include
#include
#include
using namespace std;
int main()
{
setlocale(LC_ALL, "en_US.UTF-8");
wchar_t str[] = L"83.201";
wchar_t *end;
double value;
value = wcstod(str,&end);
wcout << L"Wide String = " << str << endl;
wcout << L"Double value = " << value << endl;
wcout << L"End String = " << end << endl;
return 0;
}
运行该程序时,输出为:
Wide String = 83.201
Double value = 83.201
End String =
wcstod() 函数的有效浮点值包括一个可选的+或-号,后跟以下一组值:
#include
#include
#include
using namespace std;
int main()
{
setlocale(LC_ALL, "en_US.UTF-8");
wchar_t str1[] = L"-136.31e-2End\u03c8";
wchar_t str2[] = L"0x11a.2c\u05ea";
wchar_t *end;
double value;
value = wcstod(str1,&end);
wcout << L"Wide String = " << str1 << endl;
wcout << L"Double value = " << value << endl;
wcout << L"End String = " << end << endl;
value = wcstod(str2,&end);
wcout << L"Wide String = " << str2 << endl;
wcout << L"Double value = " << value << endl;
wcout << L"End String = " << end << endl;
return 0;
}
运行该程序时,输出为:
Wide String = -136.31e-2Endψ
Double value = -1.3631
End String = Endψ
Wide String = 0x11a.2cת
Double value = 282.172
End String = ת
#include
#include
#include
using namespace std;
int main()
{
setlocale(LC_ALL, "en_US.UTF-8");
wchar_t str1[] = L"-inFinityx\u03a3y";
wchar_t str2[] = L"NaN11\u0429";
wchar_t *end;
double value;
value = wcstod(str1,&end);
wcout << L"Wide String = " << str1 << endl;
wcout << L"Double value = " << value << endl;
wcout << L"End String = " << end << endl;
value = wcstod(str2,&end);
wcout << L"Wide String = " << str2 << endl;
wcout << L"Double value = " << value << endl;
wcout << L"End String = " << end << endl;
return 0;
}
运行该程序时,输出为:
Wide String = -inFinityxΣy
Double value = -inf
End String = xΣy
Wide String = NaN11Щ
Double value = nan
End String = 11Щ
通常,wcstod() 函数的有效浮点参数具有以下形式:
[whitespace] [- | +] [digits] [.digits] [ {e | E }[- | +]digits]
直到主非空白字符被找到wcstod() 函数将忽略所有的前导空白字符 。
然后,从该字符开始,它需要尽可能多的字符 ,以形成有效的浮点表示形式并将其转换为浮点值。最后一个有效字符之后, 字符串剩余的内容将存储在str_end指向的对象中。
#include
#include
#include
using namespace std;
int main()
{
setlocale(LC_ALL, "en_US.UTF-8");
wchar_t str[] = L" 21.69\u04f8aa";
wchar_t *end;
double value;
value = wcstod(str,&end);
wcout << L"Wide String = " << str << endl;
wcout << L"Double value = " << value << endl;
wcout << L"End String = " << end << endl;
return 0;
}
运行该程序时,输出为:
Wide String = 21.69Ӹaa
Double value = 21.69
End String = Ӹaa