名稱空間
變體
操作

std::chrono::operator<<(std::chrono::day)

來自 cppreference.com
< cpp‎ | chrono‎ | day
 
 
 
 
定義於標頭檔案 <chrono>
template< class CharT, class Traits >

std::basic_ostream<CharT, Traits>&

    operator<<( std::basic_ostream<CharT, Traits>& os, const std::chrono::day& d );
(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>("...")"..." 如果 CharTchar,並且是 L"..." 如果 CharTwchar_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 的格式化支援
(類模板特化) [編輯]