Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      std::to_wstring

      From cppreference.com
      <cpp‎ |string‎ |basic string
       
       
       
      std::basic_string
       
      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(longlong value);
      (3)(since C++11)
      std::wstring to_wstring(unsigned value);
      (4)(since C++11)
      std::wstring to_wstring(unsignedlong value);
      (5)(since C++11)
      std::wstring to_wstring(unsignedlonglong 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(longdouble value);
      (9)(since C++11)

      Converts a numeric value tostd::wstring.

      Letbuf be an internal to the conversion functions buffer, sufficiently large to contain the result of conversion.

      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 bystd::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).
      (until C++26)
      1-9) Converts a numeric value to a wide string as if bystd::format(L"{}", value).
      (since C++26)

      Contents

      [edit]Parameters

      value - a numeric value to convert

      [edit]Return value

      A wide string holding the converted value.

      [edit]Exceptions

      May throwstd::bad_alloc from thestd::wstring constructor.

      [edit]Example

      Run this code
      #include <iostream>#include <string> int main(){for(constdouble 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.43to_wstring: 23.430000 std::wcout: 1e-09to_wstring: 0.000000 std::wcout: 1e+40to_wstring: 10000000000000000303786028427003666890752.000000 std::wcout: 1e-40to_wstring: 0.000000 std::wcout: 1.23457e+08to_wstring: 123456789.000000

      [edit]See also

      (C++11)
      converts an integral or floating-point value tostring
      (function)[edit]
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/string/basic_string/to_wstring&oldid=153702"

      [8]ページ先頭

      ©2009-2025 Movatter.jp