std::wcstof, std::wcstod, std::wcstold
cppreference.com
<tbody>
</tbody>
float wcstof( const wchar_t* str, wchar_t** str_end ); |
( C++11) | |
double wcstod( const wchar_t* str, wchar_t** str_end ); |
||
long double wcstold( const wchar_t* str, wchar_t** str_end ); |
( C++11) | |
, str.
( std::iswspace), . , . :
- . :
|
( C++11) |
, str_end, . str_end , .
| str | , | |
| str_end |
, str . , HUGE_VAL, HUGE_VALF HUGE_VALL. , 0.
#include <cerrno>
#include <clocale>
#include <cwchar>
#include <iostream>
#include <string>
int main()
{
std::setlocale(LC_ALL, "en_US.utf8");
const wchar_t* p = L"111.11 -2.22 0X1.BC70A3D70A3D7P+6 -Inf 1.18973e+4932zzz";
wchar_t* end;
std::wcout << L" L\"" << p << "\":\n";
for (double f = std::wcstod(p, &end); p != end; f = std::wcstod(p, &end))
{
std::wcout << " '" << std::wstring(p, end-p) << "' -> ";
p = end;
if (errno == ERANGE)
{
std::wcout << L" , ";
errno = 0;
}
std::wcout << f << '\n';
}
if (std::setlocale(LC_NUMERIC, "de_DE.utf8"))
{
std::wcout << L" de_DE.utf8:\n";
std::wcout << L" '123.45' -> " << std::wcstod(L"123.45", 0) << L'\n';
std::wcout << L" '123,45' -> " << std::wcstod(L"123,45", 0) << L'\n';
}
}
:
L"111.11 -2.22 0X1.BC70A3D70A3D7P+6 -Inf 1.18973e+4932zzz":
'111.11' -> 111.11
' -2.22' -> -2.22
' 0X1.BC70A3D70A3D7P+6' -> 111.11
' -Inf' -> -inf
' 1.18973e+4932' -> , inf
de_DE.utf8:
'123.45' -> 123
'123,45' -> 123.45
| () | |
C wcstof
| |