std::time_get<CharT,InputIt>:: get_date, std::time_get<CharT,InputIt>:: do_get_date
|
헤더에 정의됨
<locale>
|
||
|
public
:
iter_type get_date
(
iter_type beg, iter_type end,
std::
ios_base
&
str,
|
(1) | |
|
protected
:
virtual
iter_type do_get_date
(
iter_type beg, iter_type end,
std::
ios_base
&
str,
|
(2) | |
do_get_date
를 호출합니다.
[
beg
,
end
)
에서 연속된 문자들을 읽어들이고, 이 로캘에서 예상되는 기본 형식(
| date_order() | 형식 |
|---|---|
no_order
|
"%m/%d/%y" |
dmy
|
"%d/%m/%y" |
mdy
|
"%m/%d/%y" |
ymd
|
"%y/%m/%d" |
ydm
|
"%y/%d/%m" |
목차 |
매개변수
| beg | - | 파싱할 시퀀스의 시작을 지정하는 반복자 |
| end | - | 파싱할 시퀀스의 끝 바로 다음을 가리키는 반복자 |
| str | - | 이 함수가 필요할 때 로케일 패싯을 얻기 위해 사용하는 스트림 객체, 예를 들어 std::ctype 으로 공백을 건너뛰거나 std::collate 으로 문자열을 비교할 때 사용됨 |
| err | - | 이 함수에 의해 오류를 표시하기 위해 수정되는 스트림 오류 플래그 객체 |
| t | - | 이 함수 호출의 결과를 저장할 std::tm 객체에 대한 포인터 |
반환값
유효한 날짜의 일부로 인식된 문자 범위
[
beg
,
end
)
에서 마지막 문자 바로 다음을 가리키는 반복자.
참고 사항
기본 날짜 형식의 알파벳 구성 요소(있는 경우)에 대해 이 함수는 일반적으로 대소문자를 구분하지 않습니다.
구문 분석 오류가 발생하면, 이 함수의 대부분 구현에서는 * t 을 수정하지 않고 그대로 둡니다.
구현체는 표준에서 요구하는 형식 외에도 다른 날짜 형식을 지원할 수 있습니다.
예제
#include <ctime> #include <iostream> #include <iterator> #include <locale> #include <sstream> void try_get_date(const std::string& s) { std::cout << "Parsing the date out of '" << s << "' in the locale " << std::locale().name() << '\n'; std::istringstream str(s); std::ios_base::iostate err = std::ios_base::goodbit; std::tm t; const std::time_get<char>& facet = std::use_facet<std::time_get<char>>(str.getloc()); std::istreambuf_iterator<char> ret = facet.get_date({str}, {}, str, err, &t); str.setstate(err); if (str) { std::cout << "Day: " << t.tm_mday << ' ' << "Month: " << t.tm_mon + 1 << ' ' << "Year: " << t.tm_year + 1900 << '\n'; } else { std::cout << "Parse failed. Unparsed string: "; std::copy(ret, {}, std::ostreambuf_iterator<char>(std::cout)); std::cout << '\n'; } } int main() { std::locale::global(std::locale("en_US.utf8")); try_get_date("02/01/2013"); try_get_date("02-01-2013"); std::locale::global(std::locale("ja_JP.utf8")); try_get_date("2013年02月01日"); }
출력:
Parsing the date out of '02/01/2013' in the locale en_US.utf8 Day: 1 Month: 2 Year: 2013 Parsing the date out of '02-01-2013' in the locale en_US.utf8 Parse failed. Unparsed string: -01-2013 Parsing the date out of '2013年02月01日' in the locale ja_JP.utf8 Day: 1 Month: 2 Year: 2013
결함 보고서
다음의 동작 변경 결함 보고서들은 이전에 발표된 C++ 표준에 소급 적용되었습니다.
| DR | 적용 대상 | 게시된 동작 | 올바른 동작 |
|---|---|---|---|
| LWG 248 | C++98 |
eofbit
가 끝 반복자에 도달할 때 설정되지 않음
|
유효한 날짜가 읽히지 않은 경우
eofbit
를 설정함
|
| LWG 461 | C++98 |
do_get_date
가 지역화된 날짜 표현을 파싱해야 했음
|
date_order() 로 결정된 형식으로 파싱함 |
참고 항목
|
(C++11)
|
지정된 형식의 날짜/시간 값을 파싱합니다
(함수 템플릿) |