Namespaces
Variants

std:: money_get

From cppreference.net
헤더에 정의됨 <locale>
template <

class CharT,
class InputIt = std:: istreambuf_iterator < CharT >

> class money_get ;

클래스 템플릿 std::money_get 는 문자 스트림에서 화폐 값을 파싱하기 위한 규칙을 캡슐화합니다. 표준 I/O 매니퓰레이터 std::get_money 는 I/O 스트림의 로캘에 있는 std::money_get 패싯을 사용합니다.

cpp/locale/locale/facet std-money get-inheritance.svg

상속 다이어그램

만약 std::money_get 특수화가 표준 라이브러리에서 제공된다는 보장이 없는 경우(아래 참조), 해당 get() do_get() 멤버 함수의 동작은 명세된 대로 보장되지 않습니다.

목차

특수화

표준 라이브러리는 다음과 같은 특수화를 제공함을 보장합니다 (이들은 모든 locale 객체에 의해 구현되어야 하는 요구사항 입니다):

헤더 파일에 정의됨 <locale>
std :: money_get < char > 좁은 문자열로 표현된 통화 값 파싱
std :: money_get < wchar_t > 넓은 문자열로 표현된 통화 값 파싱

또한, 표준 라이브러리는 다음 타입 요구사항을 충족하는 모든 특수화를 제공하는 것도 보장됩니다:

중첩 타입

타입 정의
char_type CharT
string_type std:: basic_string < CharT >
iter_type InputIt

데이터 멤버

멤버 설명
std::locale::id id [static] facet 의 식별자

멤버 함수

새로운 money_get 패싯을 생성함
(public member function)
do_get 을 호출함
(public member function)

보호된 멤버 함수

money_get 패싯을 파괴함
(protected 멤버 함수)
[virtual]
입력 스트림에서 금전 값을 파싱함
(virtual protected 멤버 함수)

예제

#include <iomanip>
#include <iostream>
#include <iterator>
#include <locale>
#include <sstream>
int main()
{
    std::string str = "$1.11 $2.22 $3.33";
    std::cout << std::fixed << std::setprecision(2);
    std::cout << '\"' << str << "\" parsed with the I/O manipulator: ";
    std::istringstream s1(str);
    s1.imbue(std::locale("en_US.UTF-8"));
    long double val;
    while (s1 >> std::get_money(val))
        std::cout << val / 100 << ' ';
    std::cout << '\n';
    str = "USD  1,234.56";
    std::cout << '\"' << str << "\" parsed with the facet directly: ";
    std::istringstream s2(str);
    s2.imbue(std::locale("en_US.UTF-8"));
    auto& f = std::use_facet<std::money_get<char>>(s2.getloc());
    std::ios_base::iostate err;
    std::istreambuf_iterator<char> beg(s2), end;
    f.get(beg, end, true, s2, err, val);
    std::cout << val / 100 << '\n';
}

출력:

"$1.11 $2.22 $3.33" parsed with the I/O manipulator: 1.11 2.22 3.33
"USD  1,234.56" parsed with the facet directly: 1234.56

결함 보고서

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

DR 적용 대상 게시된 동작 올바른 동작
LWG 427 C++98 money_get 은 모든 CharT 를 수용하도록 보장됨
(iostream 구성 요소가 인스턴스화될 수 있는
모든 문자 요구사항을 충족하는 경우)
char ,
wchar_t 및 다른 구현 정의
문자 타입만 수용하도록 보장
LWG 2392 C++98 문자 타입 CharT 만이
money_get 에 의해 수용될 수 있음이 보장됨
구현 정의 문자 컨테이너 타입도
수용할 수 있도록 보장 가능

참고 항목

std::money_get std::money_put 에서 사용하는 통화 서식 매개변수를 정의함
(클래스 템플릿)
통화 값을 문자 시퀀스로 출력하기 위해 서식을 지정함
(클래스 템플릿)
(C++11)
통화 값을 파싱함
(함수 템플릿)