std::chrono::from_stream (std::chrono::duration)
Min standard notice:
Header: <chrono>
Attempts to parse the input stream is into the std::chrono::duration d, interpreted as the time of day since midnight, according to the format string fmt.
# Declarations
template< class CharT, class Traits, class Rep, class Period,
class Alloc = std::allocator<CharT> >
std::basic_istream<CharT, Traits>&
from_stream( std::basic_istream<CharT, Traits>& is, const CharT* fmt,
std::chrono::duration<Rep, Period>& d,
std::basic_string<CharT, Traits, Alloc>* abbrev = nullptr,
std::chrono::minutes* offset = nullptr );
(since C++20)
# Parameters
is: an input streamfmt: a format string (see below)d: std::chrono::duration object to hold the parse resultabbrev: if not null, pointer to an object that will hold the time zone abbreviation or name corresponding to the %Z specifieroffset: if not null, pointer to an object that will hold the offset from UTC corresponding to the %z specifier
# Return value
is
# Example
#include <chrono>
#include <iostream>
#include <locale>
#include <sstream>
int main()
{
std::istringstream is{"16:14:34"};
is.imbue(std::locale("en_US.utf-8"));
std::chrono::hours hh;
is >> std::chrono::from_stream("%H:%M:%S", hh);
is.fail() ? std::cout << "Parse failed!\n" : std::cout << hh.count() << '\n';
}