A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://en.cppreference.com/w/cpp/algorithm/../../cpp/algorithm/../chrono/year/operator_ltlt.html below:

std::chrono::operator<<(std::chrono::year) - cppreference.com

Forms a std::basic_string<CharT> s consisting of the year value stored in y formatted as a decimal number, left-padded with ​0​ to four digits if the result would otherwise be less than four digits. Then, if !y.ok(), append " is not a valid year" to the formatted string. Inserts that string into os.

Equivalent to

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

where STATICALLY_WIDEN<CharT>("...") is "..." if CharT is char, and L"..." if CharT is wchar_t.

[edit] Return value

os

[edit] Example
#include <chrono>
#include <iostream>
 
int main()
{
    constexpr std::chrono::year y1{2020}, y2{-020}, y3{98304};
    std::cout << y1 << '\n'
              << y2 << '\n'
              << y3 << '\n';
}

Possible output:

2020
-0016
-32768 is not a valid year
[edit] See also

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4