Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      std::chrono::operator<<(std::chrono::day)

      From cppreference.com
      <cpp‎ |chrono‎ |day
       
       
      Date and time library
       
       
      Defined in header<chrono>
      template<class CharT,class Traits>

      std::basic_ostream<CharT, Traits>&

          operator<<(std::basic_ostream<CharT, Traits>& os,conststd::chrono::day& d);
      (since C++20)

      Forms astd::basic_string<CharT>s consisting of the day value stored ind formatted as a decimal number, with a leading zero if the result would otherwise be a single decimal digit. Then, if!d.ok(), append" is not a valid day" to the formatted string. Inserts that string intoos.

      Equivalent to

      return os<<(d.ok()?
         std::format(STATICALLY_WIDEN<CharT>("{:%d}"), d):
         std::format(STATICALLY_WIDEN<CharT>("{:%d} is not a valid day"), d));

      whereSTATICALLY_WIDEN<CharT>("...") is"..." ifCharT ischar, andL"..." ifCharT iswchar_t.

      [edit]Return value

      os

      [edit]Example

      Run this code
      #include <chrono>#include <iostream> int main(){constexprstd::chrono::day d1{31}, d2{7}, d3{42}, d4{};std::cout<< d1<<'\n'<< d2<<'\n'<< d3<<'\n'<< d4<<'\n';}

      Possible output:

      310742 is not a valid day00 is not a valid day

      [edit]See also

      (C++20)
      stores formatted representation of the arguments in a new string
      (function template)[edit]
      formatting support forday
      (class template specialization)[edit]
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/chrono/day/operator_ltlt&oldid=161527"

      [8]ページ先頭

      ©2009-2025 Movatter.jp