• Class / Function / Type

      std::
    • Header file

      <>
    • Other / All

    最終更新日時(UTC):
    が更新

    履歴 編集

    function
    <chrono>

    std::chrono::operator<<

    namespace std::chrono {
      template <class charT, class traits>
      std::basic_ostream<charT, traits>&
        operator<<(std::basic_ostream<charT, traits>& os, const year& y); // (1) C++20
    }
    

    概要

    yearオブジェクトを出力ストリームに出力する。

    戻り値

    便宜上のリテラルキャストSTATICALLY-WIDENを導入する。STATICALLY-WIDEN<charT>("...")は、charTcharである場合は"..."charTwchar_tである場合はL"..."を意味する。

    • (1) : 以下と等価:
      return os << (y.ok() ?
        format(STATICALLY-WIDEN<charT>("{:%Y}"), y) :
        format(STATICALLY-WIDEN<charT>("{:%Y} is not a valid year"), y));
      

    備考

    • このフォーマットでは、4桁ゼロ埋めで年の整数値が出力される。3桁の日を出力する場合、0123のように先頭にゼロがつく

    #include <iostream>
    #include <chrono>
    
    namespace chrono = std::chrono;
    
    int main()
    {
      std::cout << chrono::year{2020} << std::endl;
    }
    

    出力

    2020
    

    バージョン

    言語

    • C++20

    処理系

    関連項目