std::to_wstring(3)
π std::to_wstring(3) π
okay bestie, welcome to std::to_wstring from the C++ Standard Libary β yes, that's their spelling, not mine π. This whole page is about turning numbers into wide strings, and it's honestly giving βsmall utility, main character energyβ β¨. Let's go.
β¨ NAME β¨
std::to_wstring - std::to_wstring
πΈ SYNOPSIS πΈ
Defined in header <string>
std::wstring to_wstring( int value ); (1) (since C++11)
std::wstring to_wstring( long value ); (2) (since C++11)
std::wstring to_wstring( long long value ); (3) (since C++11)
std::wstring to_wstring( unsigned value ); (4) (since C++11)
std::wstring to_wstring( unsigned long value ); (5) (since C++11)
std::wstring to_wstring( unsigned long long value ); (6) (since C++11)
std::wstring to_wstring( float value ); (7) (since C++11)
std::wstring to_wstring( double value ); (8) (since C++11)
std::wstring to_wstring( long double value ); (9) (since C++11)
Converts a numeric value to std::wstring. That's the vibe. π
Okay so let buf be an internal to the conversion functions buffer, sufficiently large to contain the result of conversion. Like, there's a buffer, it's big enough, we don't gotta worry about it. π«Ά
1)β Converts a signed decimal integer to a wide string as if bystd::swprintf(buf, sz, L"%d", value).2)β Converts a signed decimal integer to a wide string as if bystd::swprintf(buf, sz, L"%ld", value).3)β Converts a signed decimal integer to a wide string as if bystd::swprintf(buf, sz, L"%lld", value).4)β Converts an unsigned decimal integer to a wide string as if by (until C++26)std::swprintf(buf, sz, L"%u", value).5)β Converts an unsigned decimal integer to a wide string as if bystd::swprintf(buf, sz, L"%lu", value).6)β Converts an unsigned decimal integer to a wide string as if bystd::swprintf(buf, sz, L"%llu", value).7,8)β Converts a floating point value to a wide string as if bystd::swprintf(buf, sz, L"%f", value).9)β Converts a floating point value to a wide string as if bystd::swprintf(buf, sz, L"%Lf", value).1-9)β (since C++26) Converts a numeric value to a wide string as if bystd::format(L"{}", value).
π PARAMETERS π
valueβ a numeric value to convert.
π RETURN VALUE π
A wide string holding the converted value. Periodt. π
π¦ EXCEPTIONS π¦
May throw std::bad_alloc from the std::wstring constructor. So yeah, allocate responsibly, bestie π.
π EXAMPLE π
// Run this code
#include <iostream>
#include <string>
int main()
{
for (const double f : {23.43, 1e-9, 1e40, 1e-40, 123456789.0})
std::wcout << "std::wcout: " << f << '\n'
<< "to_wstring: " << std::to_wstring(f) << "\n\n";
}
π OUTPUT: π
std::wcout: 23.43
to_wstring: 23.430000
std::wcout: 1e-09
to_wstring: 0.000000
std::wcout: 1e+40
to_wstring: 10000000000000000303786028427003666890752.000000
std::wcout: 1e-40
to_wstring: 0.000000
std::wcout: 1.23457e+08
to_wstring: 123456789.000000
π SEE ALSO π
to_stringβ converts an integral or floating-point value to string (C++11) (function).
mwah π β source/version: http://cppreference.com Β· date: 2024.06.10 Β· page: std::to_wstring(3). slay and goodbye π¦β¨
π¦ where this page comes from
- nixpkgs unstable: stdman 2024.07.05
- opensuse-leap 16.0: stdman 2024.07.05-bp160.1.9 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms