CppDS.com

C++ 98 11 14 17 20 手册

std::chrono::operator<<(std::chrono::year)

来自cppreference.com
< cpp‎ | chrono‎ | year
 
 
日期和时间工具
(C++11)
(C++11)
当天时刻
(C++20)



(C++20)(C++20)(C++20)(C++20)
时钟
(C++20)
                                             
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
日历
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
时区
(C++20)
(C++20)
(C++20)
(C++20)
C 风格日期和时间
 
 
template <class CharT, class Traits>

std::basic_ostream<CharT, Traits>&

operator<<(std::basic_ostream<CharT, Traits>& os, const std::chrono::year& y);
(C++20 起)

构成由格式化为十进制数的存储于 y 的年值,若结果会少于四位则左填充 0 到四位组成的 std::basic_string<CharT> s 。然后若 !y.ok() 则后附 " is not a valid year" 到格式化的字符串。插入该字符串到 os 中。

等价于

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

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

返回值

os

参阅

(C++20)
在新 string 中存储参数的格式化表示
(函数模板)
std::formatter 的特化,按照提供的格式格式化 year
(类模板特化)
关闭