std::chrono::operator<<(std::chrono::day)
來自 cppreference.com
定義於標頭檔案 <chrono> |
||
template< class CharT, class Traits > std::basic_ostream<CharT, Traits>& |
(C++20 起) | |
構成一個 std::basic_string<CharT> s
,其中包含儲存在 d 中以十進位制數字格式化的日期值,如果結果本來是單個十進位制數字,則前面會有一個前導零。然後,如果 !d.ok(),則將 " is not a valid day" 附加到格式化字串。將該字串插入到 os 中。
等價於
return os << (d.ok() ?
std::format(STATICALLY_WIDEN<CharT>("{:%d}"), d) :
std::format(STATICALLY_WIDEN<CharT>("{:%d} is not a valid day"), d));
其中 STATICALLY_WIDEN<CharT>("...") 是 "..." 如果 CharT
是 char,並且是 L"..." 如果 CharT
是 wchar_t。
[編輯] 返回值
os
[編輯] 示例
執行此程式碼
#include <chrono> #include <iostream> int main() { constexpr std::chrono::day d1{31}, d2{7}, d3{42}, d4{}; std::cout << d1 << '\n' << d2 << '\n' << d3 << '\n' << d4 << '\n'; }
可能的輸出
31 07 42 is not a valid day 00 is not a valid day
[編輯] 參閱
(C++20) |
將引數的格式化表示儲存在新字串中 (函式模板) |
day 的格式化支援(類模板特化) |