std::chrono::operator<<(std::chrono::year_month_day)

来自cppreference.com
 
 
 
 
在标头 <chrono> 定义
template< class CharT, class Traits >

std::basic_ostream<CharT, Traits>&
    operator<<( std::basic_ostream<CharT, Traits>& os,

                const std::chrono::year_month_day& ymd );
(C++20 起)

输出 ymd 的文本表示到流 os 中。其首先构成一个 std::basic_string<CharT> s,它由格式为 yyyy-mm-dd(同 formatter 用 %F 说明符的输出)的日期文本表示组成。然后,若 !ymd.ok() 则后附 " is not a valid date"s。插入 sos 中。

等价于

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

其中 STATICALLY_WIDEN<CharT>("...")CharTchar 时为 "...",而当 CharTwchar_t 时为 L"..."

返回值

os

示例

参阅

(C++20)
在新字符串中存储参数的格式化表示
(函数模板)
year_month_day 的格式化支持
(类模板特化)