Skip to content

Latest commit

 

History

History
66 lines (51 loc) · 1.68 KB

formatter.md

File metadata and controls

66 lines (51 loc) · 1.68 KB

formatter

  • chrono[meta header]
  • std[meta namespace]
  • class[meta id-type]
  • cpp20[meta cpp]
namespace std {
  template <class charT>
  struct formatter<chrono::month_day, charT>;
}

概要

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

フォーマットフラグとしては、daymonthで利用可能なフォーマットフラグを使用できる。

#include <iostream>
#include <chrono>
#include <format>

namespace chrono = std::chrono;

int main() {
  chrono::month_day date = chrono::March/1;

  // デフォルトフォーマットはoperator<<と同じ
  std::cout << std::format("1 : {}", date) << std::endl;

  std::cout << std::format("2 : {:%B/%d}", date) << std::endl;
  std::cout << std::format("3 : {:%m/%d}", date) << std::endl;
  std::cout << std::format("4 : {:%m月%d日}", date) << std::endl;

  // ロケール依存の出力
  std::cout << std::format(std::locale("ja_JP.UTF-8"), "5 : {:%b}", date) << std::endl;
}
  • std::format[link /reference/chrono/format.md]
  • std::locale[link /reference/locale/locale.md]
  • chrono::March[link /reference/chrono/month_constants.md]

出力

1 : Mar/01
2 : March/01
3 : 03/01
4 : 03月01日
5 : 3月

バージョン

言語

  • C++20

処理系

関連項目