std::chrono::from_stream (std::chrono::duration)

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

# 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';
}

# See also