std::chrono::operator<< (std::chrono::duration)

From cppreference.com
< cpp‎ | chrono‎ | duration
 
 
 
Date and time utilities
(C++11)
(C++11)
Clocks
(C++20)
                                                  
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
Calendars
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
Time zones
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
C-style date and time
 
 
Defined in header <chrono>
template <class CharT, class Traits, class Rep, class Period>

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

               const std::chrono::duration<Rep, Period>& d);
(since C++20)

Inserts a textual representation of d into os. The behavior is undefined if CharT is neither char or wchar_t, or if Rep is neither a floating-point type nor a integral type with conversion rank equal to or greater than short.

Behaves as if it forms a std::basic_string<CharT, Traits> str initially consisting of the characters in std::to_string(d.count()) (if CharT is char) or std::to_wstring(d.count()) (if CharT is wchar_t). Appends to str a suffix based on Period::type according to the following table, and inserts str into the stream with os << str;.

Period::type Suffix
std::atto as
std::femto fs
std::pico ps
std::nano ns
std::micro µs (U+00B5)
std::milli ms
std::centi cs
std::deci ds
std::ratio<1> s
std::deca das
std::hecto hs
std::kilo ks
std::mega Ms
std::giga Gs
std::tera Ts
std::peta Ps
std::exa Es
std::ratio<60> min
std::ratio<3600> h
None of the above, and Period::type::den == 1 [num]s
None of the above [num/den]s

For std::micro, if the character µ (U+00B5) cannot be represented in the encoding used for CharT, the suffix "us" is used instead.

For the last two rows of the table, num and den in the suffix are Period::type::num and Period::type::den formatted as a decimal number with no leading zeroes, respectively.

Return value

A reference to the stream, i.e., os.

Notes

d.count() is formatted using the rules of std::to_string/std::to_wstring. In particular, if Rep is a floating-point type, it is always formatted with 6 digits after the decimal point, and the number of significant digits in the resulting string may be zero if d.count() is small.

See also

(C++20)
outputs a duration into a stream according to the provided format
(function template)
performs stream input and output on strings
(function template)
(C++11)
converts an integral or floating point value to string
(function)
converts an integral or floating point value to wstring
(function)