Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      std::time_put_byname

      From cppreference.com
      <cpp‎ |locale
       
       
       
      Localization library
       
      Defined in header<locale>
      template<

         class CharT,
         class OutputIt=std::ostreambuf_iterator<CharT>

      >class time_put_byname:publicstd::time_put<CharT, OutputIt>

      std::time_put_byname is astd::time_put facet which encapsulates time and date formatting rules of the locale specified at its construction.

      Contents

      [edit]Specializations

      The standard library is guaranteed to provide every specialization that satisfies the following type requirements:

      [edit]Nested types

      Type Definition
      char_typeCharT
      iter_typeOutputIt

      [edit]Member functions

      (constructor)
      constructs a newtime_put_byname facet
      (public member function)[edit]
      (destructor)
      destroys atime_put_byname facet
      (protected member function)[edit]
      [edit]

      std::time_put_byname::time_put_byname

      explicit time_put_byname(constchar* name,std::size_t refs=0);
      explicit time_put_byname(conststd::string& name,std::size_t refs=0);
      (since C++11)

      Constructs a newstd::time_put_byname facet for a locale withname.

      refs is used for resource management: ifrefs==0, the implementation destroys the facet, when the laststd::locale object holding it is destroyed. Otherwise, the object is not destroyed.

      Parameters

      name - the name of the locale
      refs - the number of references that link to the facet
      [edit]

      std::time_put_byname::~time_put_byname

      protected:
      ~time_put_byname();

      Destroys the facet.

      Inherited fromstd::time_put

      [edit]Data members

      Member Description
      std::locale::idid[static] the identifier of thefacet

      Member functions

      invokesdo_put
      (public member function ofstd::time_put<CharT,OutputIt>)[edit]

      Protected member functions

      [virtual]
      formats date/time and writes to output stream
      (virtual protected member function ofstd::time_put<CharT,OutputIt>)[edit]

      [edit]Example

      Prints current time using the "C" locale with thetime_put facet replaced by variousstd::time_put_byname facets. The result shown was obtained using the clang compiler.

      Run this code
      #include <codecvt>#include <ctime>#include <iomanip>#include <iostream> int main(){std::time_t t=std::time(nullptr);std::wbuffer_convert<std::codecvt_utf8<wchar_t>> conv(std::cout.rdbuf());std::wostream out(&conv);     out.imbue(std::locale(out.getloc(),                          new std::time_put_byname<wchar_t>("ja_JP.utf8")));    out<<std::put_time(std::localtime(&t), L"%A %c")<<'\n';     out.imbue(std::locale(out.getloc(),                          new std::time_put_byname<wchar_t>("ru_RU.utf8")));    out<<std::put_time(std::localtime(&t), L"%A %c")<<'\n';     out.imbue(std::locale(out.getloc(),                          new std::time_put_byname<wchar_t>("sv_SE.utf8")));    out<<std::put_time(std::localtime(&t), L"%A %c")<<'\n';}

      Possible output:

      木曜日 2023年10月05日 19時44分51秒Четверг Чт 05 окт 2023 19:44:51torsdag tor  5 okt 2023 19:44:51

      [edit]See also

      formats contents ofstd::tm for output as character sequence
      (class template)[edit]
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/locale/time_put_byname&oldid=179759"

      [8]ページ先頭

      ©2009-2025 Movatter.jp