std::chrono::operator<<(std::chrono::duration) (3) - Linux Man Pages

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

NAME

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

Synopsis


Defined in header <chrono>
template <class CharT, class Traits, class Rep, class Period>
std::basic_ostream<CharT, Traits>& (since C++20)
operator<<(std::basic_ostream<CharT, Traits>& os,
const std::chrono::duration<Rep, Period>& d);


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


to_stream outputs a duration into a stream according to the provided format
           (function template)
(C++20)
           performs stream input and output on strings
operator<< (function template)
operator>>


to_string converts an integral or floating point value to string
           (function)
(C++11)


to_wstring converts an integral or floating point value to wstring
           (function)
(C++11)