• Class / Function / Type

      std::
    • Header file

      <>
    • Other / All

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

    履歴 編集

    class
    <chrono>

    std::formatter

    namespace std {
      template <class charT>
      struct formatter<chrono::year_month, charT>;
    }
    

    概要

    year_month_dayクラスに対するstd::formatterクラステンプレートの特殊化。

    monthyearで利用可能なフォーマットフラグを使用できる。

    #include <iostream>
    #include <chrono>
    #include <format>
    
    namespace chrono = std::chrono;
    using namespace std::chrono_literals;
    
    int main() {
      chrono::year_month date = 2020y/3;
    
      // デフォルトフォーマットはoperator<<と同じ
      std::cout << std::format("1 : {}", date) << std::endl;
      std::cout << std::format("2 : {:%Y/%b}", date) << std::endl;
      std::cout << std::format("3 : {:%Y年%m月}", date) << std::endl;
    }
    

    出力

    1 : 2020/Mar
    2 : 2020/Mar
    3 : 2020年03月
    

    バージョン

    言語

    • C++20

    処理系

    関連項目