std::formatter

std::formatter (std::chrono::year_month_weekday 특수화)

std::chrono::year_month_weekday 값을 포맷할 수 있게 해주는 std::formatter 특수화예요. std::formatstd::print에서 이 타입을 출력할 수 있게 해줘요. C++20부터 있어요.

출처: cppreference

본문

<chrono> 헤더에 정의돼 있고, std::formatter<std::chrono::year_month_weekday> 특수화예요. std::format·std::print 계열에서 이 값을 chrono 형식 지정 문법에 따라 포맷해요.

사용 가능한 chrono 포맷 지정자 예:

  • %Y — 네 자리 연도
  • %b / %B — 월 약어 / 전체 월 이름
  • %a / %A — 요일 약어 / 전체 요일
  • %m — 두 자리 월

기본(형식 지정 없음) 출력은 연·월·n번째 요일 형태를 나타내요.

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

int main()
{
    using namespace std::chrono;
    year_month_weekday ymwd{2023y/September/Friday[2]};
    std::cout << std::format("{:%Y-%b-%A}", ymwd) << '\n'; // 2023-Sep-Friday
}

더 알아보기 (Learn more)

cppreference