Namespaces
Variants

std::time_get<CharT,InputIt>:: get_monthname, std::time_get<CharT,InputIt>:: do_get_monthname

From cppreference.net
헤더 파일에 정의됨 <locale>
public :

iter_type get_monthname ( iter_type beg, iter_type end, std:: ios_base & str,

std:: ios_base :: iostate & err, std:: tm * t ) const ;
(1)
protected :

virtual iter_type do_get_monthname ( iter_type beg, iter_type end, std:: ios_base & str,

std:: ios_base :: iostate & err, std:: tm * t ) const ;
(2)
1) Public 멤버 함수, 가장 파생된 클래스의 protected virtual 멤버 함수 do_get_monthname 을 호출합니다.
2) 시퀀스 [ beg , end ) 에서 연속적인 문자를 읽어들이고, 이 로캘에서 예상되는 기본 월 이름 형식(약어 형태일 수 있음)을 사용하여 월 이름을 파싱합니다. 이 형식은 "%b" 와 동일하며, std::get_time , time_get::get 함수 및 POSIX 함수 strptime() 에서 사용되는 형식과 같습니다.

약어 이름을 찾은 후, 전체 이름에 유효한 문자들이 이어지면, 전체 이름에 대한 모든 문자를 소비하거나 예상치 못한 문자를 찾을 때까지 계속 읽습니다. 이 경우 처음 몇 문자가 유효한 약어였더라도 구문 분석이 실패합니다.

파싱된 월은 std::tm 필드 t - > tm_mon 에 저장됩니다.

유효한 월 이름이 읽히기 전에 끝 반복자에 도달하면, 함수는 std::ios_base::eofbit err 에 설정합니다. 파싱 오류가 발생하면, 함수는 std::ios_base::failbit err 에 설정합니다.

목차

매개변수

beg - 파싱할 시퀀스의 시작을 지정하는 반복자
end - 파싱할 시퀀스의 끝 바로 다음을 가리키는 반복자
str - 필요할 때 로케일 패싯을 얻기 위해 이 함수가 사용하는 스트림 객체, 예를 들어 std::ctype 으로 공백을 건너뛰거나 std::collate 으로 문자열을 비교함
err - 오류를 표시하기 위해 이 함수에 의해 수정되는 스트림 오류 플래그 객체
t - 이 함수 호출의 결과를 보관할 std::tm 객체에 대한 포인터

반환값

유효한 월 이름의 일부로 인식된 문자 범위 [ beg , end ) 에서 마지막 문자 바로 다음을 가리키는 반복자.

참고 사항

이 함수는 일반적으로 대소문자를 구분하지 않습니다.

구문 분석 오류가 발생하면, 이 함수의 대부분 구현에서는 * t 을 수정하지 않고 그대로 둡니다.

예제

#include <ctime>
#include <iostream>
#include <iterator>
#include <locale>
#include <sstream>
#include <string_view>
void try_get_mon(std::string_view locale_name, std::string_view source)
{
    try
    {
        std::locale::global(std::locale(locale_name.data()));
    }
    catch (std::runtime_error const& ex)
    {
        std::cout << "Cannot setup locale: " << locale_name << "\n"
                     "Exception: " << ex.what() << '\n';
        return;
    }
    std::cout << "Parsing the month out of '" << source
              << "' in the locale " << std::locale().name() << '\n';
    std::istringstream str{source.data()};
    std::ios_base::iostate err = std::ios_base::goodbit;
    std::tm t;
    std::time_get<char> const& facet = std::use_facet<std::time_get<char>>(str.getloc());
    std::istreambuf_iterator<char> ret = facet.get_monthname({str}, {}, str, err, &t);
    str.setstate(err);
    std::istreambuf_iterator<char> last{};
    if (str)
    {
        std::cout << "Successfully parsed, month number is " << t.tm_mon;
        if (ret != last)
        {
            std::cout << ". Remaining content: ";
            std::copy(ret, last, std::ostreambuf_iterator<char>(std::cout));
        }
        else
            std::cout << ". The input was fully consumed";
    }
    else
    {
        std::cout << "Parse failed. Unparsed string: ";
        std::copy(ret, last, std::ostreambuf_iterator<char>(std::cout));
    }
    std::cout << '\n';
}
int main()
{
    try_get_mon("ja_JP.utf8", "2月");
    try_get_mon("th_TH.utf8", "กุมภาพันธ์");
    try_get_mon("el_GR.utf8", "Φεβ");
    try_get_mon("el_GR.utf8", "Φεβρουάριος");
    try_get_mon("en_US.utf8", "Febrile");
}

가능한 출력:

Parsing the month out of '2月' in the locale ja_JP.utf8
Successfully parsed, month number is 1. The input was fully consumed
Parsing the month out of 'กุมภาพันธ์' in the locale th_TH.utf8
Successfully parsed, month number is 1. The input was fully consumed
Parsing the month out of 'Φεβ' in the locale el_GR.utf8
Successfully parsed, month number is 1. The input was fully consumed
Parsing the month out of 'Φεβρουάριος' in the locale el_GR.utf8
Successfully parsed, month number is 1. The input was fully consumed
Parsing the month out of 'Febrile' in the locale en_US.utf8
Parse failed. Unparsed string: ile

결함 보고서

다음의 동작 변경 결함 보고서들은 이전에 발표된 C++ 표준에 소급 적용되었습니다.

DR 적용 대상 게시된 동작 올바른 동작
LWG 248 C++98 eofbit 이 끝 반복자에 도달했을 때 설정되지 않음 유효한 월 이름이 읽히지 않은 경우 eofbit 설정

참고 항목

(C++11)
지정된 형식의 날짜/시간 값을 파싱합니다
(함수 템플릿)