Namespaces
Variants
Actions

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

From cppreference.com
< cpp‎ | chrono‎ | duration
 
 
Date and time library
(C++11)
(C++20)
(C++11)
(C++11)
(C++11)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)(C++20)
(C++20)(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)(C++20)
(C++20)

 
std::chrono::duration
Member functions
Non-member functions
Helper classes
 
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.

Behaves as if it was implemented as

std::basic_ostringstream <CharT, Traits> s;
s.flags(os.flags());
s.imbue(os.getloc());
s.precision(os.precision());
s << d.count() << units_suffix; // see below
return os << s.str();

In other words, the stream flags, locale, and precision are determined by the stream, but any padding are determined using the entire output string.

The units_suffix is determined based on Period::type according to the following table.

Period::type Suffix
std::atto as
std::micro μs (U+00B5) or us, it is implementation-defined which one is used
std::deca das
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.

[edit] Return value

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

[edit] Example

This example shows the output of std::chrono::operator<< when given a duration:

Run this code
#include <chrono>
#include <iostream>
using namespace std::chrono_literals;
 
int main()
{
 constexpr auto duration = 123ms;
 std::cout << duration << '\n';
}

Output:

123ms

[edit] See also

(C++20)
stores formatted representation of the arguments in a new string
(function template) [edit]
formatting support for duration
(class template specialization) [edit]
performs stream input and output on strings
(function template) [edit]
(C++11)
converts an integral or floating-point value to string
(function) [edit]
(C++11)
converts an integral or floating-point value to wstring
(function) [edit]
Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/chrono/duration/operator_ltlt&oldid=154565"

AltStyle によって変換されたページ (->オリジナル) /