std::chrono::operator<< (std::chrono::duration)
| Defined in header <chrono>
|
||
| template <class CharT, class Traits, class Rep, class Period> std::basic_ostream<CharT, Traits>& |
(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 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.
If CharT has a 8-bit representation, the implementation is encouraged to encode "µs" as UTF-8; otherwise UTF-16 or UTF-32 is encouraged. The implementation may also substitute other encodings, include "us".
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) |
| (C++11) |
converts an integral or floating point value to wstring (function) |