Files
2025-10-25 03:02:53 +03:00

4.7 KiB
Raw Permalink Blame History

[time.duration.io]

30 Time library [time]

30.5 Class template duration [time.duration]

30.5.11 I/O [time.duration.io]

🔗

template<class charT, class traits, class Rep, class Period> basic_ostream<charT, traits>& operator<<(basic_ostream<charT, traits>& os, const duration<Rep, Period>& d);

1

#

Effects: Inserts the duration d onto the stream os as if it were implemented as follows:basic_ostringstream<charT, traits> s; s.flags(os.flags()); s.imbue(os.getloc()); s.precision(os.precision()); s << d.count() << units-suffix;return os << s.str(); where units-suffix depends on the type Period::type as follows:

  • (1.1)

    If Period::type is atto,units-suffix is "as".

  • (1.2)

    Otherwise, if Period::type is femto,units-suffix is "fs".

  • (1.3)

    Otherwise, if Period::type is pico,units-suffix is "ps".

  • (1.4)

    Otherwise, if Period::type is nano,units-suffix is "ns".

  • (1.5)

    Otherwise, if Period::type is micro, it isimplementation-defined whether units-suffix is"μs" ("\u00b5\u0073") or"us".

  • (1.6)

    Otherwise, if Period::type is milli,units-suffix is "ms".

  • (1.7)

    Otherwise, if Period::type is centi,units-suffix is "cs".

  • (1.8)

    Otherwise, if Period::type is deci,units-suffix is "ds".

  • (1.9)

    Otherwise, if Period::type is ratio<1>,units-suffix is "s".

  • (1.10)

    Otherwise, if Period::type is deca,units-suffix is "das".

  • (1.11)

    Otherwise, if Period::type is hecto,units-suffix is "hs".

  • (1.12)

    Otherwise, if Period::type is kilo,units-suffix is "ks".

  • (1.13)

    Otherwise, if Period::type is mega,units-suffix is "Ms".

  • (1.14)

    Otherwise, if Period::type is giga,units-suffix is "Gs".

  • (1.15)

    Otherwise, if Period::type is tera,units-suffix is "Ts".

  • (1.16)

    Otherwise, if Period::type is peta,units-suffix is "Ps".

  • (1.17)

    Otherwise, if Period::type is exa,units-suffix is "Es".

  • (1.18)

    Otherwise, if Period::type is ratio<60>,units-suffix is "min".

  • (1.19)

    Otherwise, if Period::type is ratio<3600>,units-suffix is "h".

  • (1.20)

    Otherwise, if Period::type is ratio<86400>,units-suffix is "d".

  • (1.21)

    Otherwise, if Period::type::den == 1,units-suffix is "[num]s".

  • (1.22)

    Otherwise, units-suffix is"[num/den]s".

In the list above, the use of num and den refers to the static data members of Period::type, which are converted to arrays of charT using a decimal conversion with no leading zeroes.

2

#

Returns: os.

🔗

template<class charT, class traits, class Rep, class Period, class Alloc = allocator<charT>> basic_istream<charT, traits>& from_stream(basic_istream<charT, traits>& is, const charT* fmt, duration<Rep, Period>& d, basic_string<charT, traits, Alloc>* abbrev = nullptr, minutes* offset = nullptr);

3

#

Effects: Attempts to parse the input stream is into the duration d using the format flags given in the NTCTS fmt as specified in [time.parse].

If the parse fails to decode a valid duration,is.setstate(ios_base::failbit) is called and d is not modified.

If %Z is used and successfully parsed, that value will be assigned to *abbrev if abbrev is non-null.

If %z (or a modified variant) is used and successfully parsed, that value will be assigned to *offset if offset is non-null.

4

#

Returns: is.