chrono_parse
chrono_parse (스트림 파싱 지정자)
std::chrono::parse는 스트림에서 시간·날짜를 지정된 포맷으로 파싱하기 위한 조작자(manipulator)를 반환해요.
출처: cppreference
본문
std::chrono::parse는 <chrono> 헤더에 정의된 함수 템플릿이에요. C++20부터 사용 가능해요.
template< class CharT, class Traits, class Alloc >
auto parse( const CharT* fmt, T& tp, ... );
fmt에 따라 스트림에서 시간·날짜를 파싱해 tp에 저장하는 manip 객체를 반환해요. 주어진 std::basic_istream<CharT, Traits> 객체 is에 대해 is >> manip 표현식이 from_stream(is, fmt, tp, ...)을 호출하도록 해요 (ADL로 찾음).
다양한 파싱 대상(시간점, 기간, day, month, year 등)을 지원하며, abbrev, offset 같은 추가 출력 인자를 받을 수 있어요.
예제 (Example)
#include <chrono>
#include <iostream>
#include <sstream>
int main()
{
std::istringstream is("2020-07-13 12:30:00");
std::chrono::sys_time<std::chrono::seconds> tp;
is >> std::chrono::parse("%F %T", tp);
std::cout << tp.time_since_epoch().count() << '\n';
}