Namespaces
Variants

std:: to_wstring

From cppreference.net
std::basic_string
Défini dans l'en-tête <string>
std:: wstring to_wstring ( int value ) ;
(1) (depuis C++11)
std:: wstring to_wstring ( long value ) ;
(2) (depuis C++11)
std:: wstring to_wstring ( long long value ) ;
(3) (depuis C++11)
std:: wstring to_wstring ( unsigned value ) ;
(4) (depuis C++11)
std:: wstring to_wstring ( unsigned long value ) ;
(5) (depuis C++11)
std:: wstring to_wstring ( unsigned long long value ) ;
(6) (depuis C++11)
std:: wstring to_wstring ( float value ) ;
(7) (depuis C++11)
std:: wstring to_wstring ( double value ) ;
(8) (depuis C++11)
std:: wstring to_wstring ( long double value ) ;
(9) (depuis C++11)

Convertit une valeur numérique en std::wstring .

Soit buf un tampon interne aux fonctions de conversion, suffisamment grand pour contenir le résultat de la conversion.

1) Convertit un entier décimal signé en une chaîne large comme avec std:: swprintf ( buf, sz, L "%d" , value ) .
2) Convertit un entier décimal signé en une chaîne large comme avec std:: swprintf ( buf, sz, L "%ld" , value ) .
3) Convertit un entier décimal signé en une chaîne large comme avec std:: swprintf ( buf, sz, L "%lld" , value ) .
4) Convertit un entier décimal non signé en une chaîne large comme avec std:: swprintf ( buf, sz, L "%u" , value ) .
5) Convertit un entier décimal non signé en une chaîne large comme avec std:: swprintf ( buf, sz, L "%lu" , value ) .
6) Convertit un entier décimal non signé en une chaîne large comme avec std:: swprintf ( buf, sz, L "%llu" , value ) .
7,8) Convertit une valeur à virgule flottante en une chaîne large comme avec std:: swprintf ( buf, sz, L "%f" , value ) .
9) Convertit une valeur à virgule flottante en une chaîne large comme avec std:: swprintf ( buf, sz, L "%Lf" , value ) .
(jusqu'en C++26)
1-9) Convertit une valeur numérique en une chaîne large comme avec std:: format ( L "{}" , value ) .
(depuis C++26)

Table des matières

Paramètres

value - une valeur numérique à convertir

Valeur de retour

Une chaîne large contenant la valeur convertie.

Exceptions

Peut lever std::bad_alloc depuis le constructeur de std::wstring .

Exemple

#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";
}

Sortie :

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

Voir aussi

(C++11)
convertit une valeur entière ou à virgule flottante en string
(fonction)