Namespaces
Variants

std:: put_money

From cppreference.net
< cpp ‎ | io ‎ | manip
헤더 파일에 정의됨 <iomanip>
template < class MoneyT >
/*unspecified*/ put_money ( const MoneyT & mon, bool intl = false ) ;
(C++11부터)

표현식에서 사용될 때 out << put_money ( mon, intl ) 는 통화 값 mon 을 현재 out 에 임베드된 로캘의 std::money_put 패싯에 지정된 방식으로 문자 표현으로 변환합니다.

out << put_money ( mon, intl ) 의 삽입 연산은 FormattedOutputFunction 으로 동작합니다.

목차

매개변수

mon - 통화 값, long double 또는 std::basic_string
intl - true 이면 국제 통화 문자열 사용, 그렇지 않으면 통화 기호 사용

반환값

지정되지 않은 타입의 객체로서

함수 f 가 다음과 같이 정의되는 경우:

template<class CharT, class Traits, class MoneyT>
void f(std::basic_ios<CharT, Traits>& str, const MoneyT& mon, bool intl)
{
    using Iter = std::ostreambuf_iterator<CharT, Traits>;
    using MoneyPut = std::money_put<CharT, Iter>;
    const MoneyPut& mp = std::use_facet<MoneyPut>(str.getloc());
    const Iter end = mp.put(Iter(str.rdbuf()), intl, str, str.fill(), mon);
    if (end.failed())
        str.setstate(std::ios_base::badbit);
}

예제

#include <iomanip>
#include <iostream>
int main()
{
    long double mon = 123.45; // or std::string mon = "123.45";
    std::cout.imbue(std::locale("en_US.UTF-8"));
    std::cout << std::showbase
              << "en_US: " << std::put_money(mon)
              << " or " << std::put_money(mon, true) << '\n';
    std::cout.imbue(std::locale("ru_RU.UTF-8"));
    std::cout << "ru_RU: " << std::put_money(mon)
              << " or " << std::put_money(mon, true) << '\n';
    std::cout.imbue(std::locale("ja_JP.UTF-8"));
    std::cout << "ja_JP: " << std::put_money(mon)
              << " or " << std::put_money(mon, true) << '\n';
}

가능한 출력:

en_US: $1.23 or USD  1.23
ru_RU: 1.23 руб or 1.23 RUB 
ja_JP: ¥123 or JPY  123

참고 항목

화폐 값을 문자 시퀀스로 출력하기 위해 형식화
(클래스 템플릿)
(C++11)
화폐 값을 파싱
(함수 템플릿)