year_from_stream

year_from_stream (year 스트림 파싱)

std::chrono::from_stream은 입력 스트림을 포맷 문자열 fmt에 따라 파싱해서 std::chrono::year에 저장해요.

출처: cppreference

본문

std::chrono::from_stream<chrono> 헤더에 정의된 함수 템플릿이에요. C++20부터 사용 가능해요.

template< class CharT, class Traits, class Alloc = std::allocator<CharT> >
std::basic_istream<CharT, Traits>&
    from_stream( std::basic_istream<CharT, Traits>& is, const CharT* fmt,
                 std::chrono::year& y,
                 std::basic_string<CharT, Traits, Alloc>* abbrev = nullptr,
                 std::chrono::minutes* offset = nullptr );

입력 스트림 is를 포맷 문자열 fmt에 따라 파싱해서 std::chrono::year y에 저장하는 것을 시도해요. 센트리 객체를 검사한 뒤 입력을 y로 파싱해요. 유효한 year로 디코딩하지 못하면 is.setstate(std::ios_base::failbit)를 호출하고 y는 수정하지 않아요.

예제 (Example)

#include <chrono>
#include <iostream>
#include <sstream>

int main()
{
    std::istringstream is("2020");
    std::chrono::year y;
    std::chrono::from_stream(is, "%Y", y);
    std::cout << int(y) << '\n'; // 2020
}

더 알아보기 (Learn more)

cppreference