std::money_put<CharT,OutputIt>:: put, do_put
|
헤더 파일에 정의됨
<locale>
|
||
|
public
:
iter_type put
(
iter_type out,
bool
intl,
std::
ios_base
&
f,
|
(1) | |
|
iter_type put
(
iter_type out,
bool
intl,
std::
ios_base
&
f,
char_type fill, const string_type & quant ) const ; |
(2) | |
|
protected
:
virtual
iter_type do_put
(
iter_type out,
bool
intl,
std::
ios_base
&
str,
|
(3) | |
|
virtual
iter_type do_put
(
iter_type out,
bool
intl,
std::
ios_base
&
str,
char_type fill, const string_type & digits ) const ; |
(4) | |
금전적 가치를 형식화하고 결과를 출력 스트림에 기록합니다.
do_put
를 호출합니다.
이전 단계의 문자 시퀀스에서 첫 번째 문자가 ct. widen ( '-' ) 와 같으면, mp. neg_format ( ) 를 호출하여 포맷팅 패턴 을 얻고, 그렇지 않으면 mp. pos_format ( ) 를 호출합니다. 여기서 mp 는 std:: moneypunct < CharT, intl > 패싯으로 str. getloc ( ) 에 임뷰된 상태입니다.
천 단위 구분자와 소수점 문자는 mp. grouping ( ) , mp. frac_digits ( ) , mp. decimal_point ( ) , 그리고 mp. thousands_sep ( ) 에 따라 필요한 대로 삽입되며, 결과 문자열은 서식 패턴에서 value 가 나타나는 출력 시퀀스에 배치됩니다.
만약 str. flags ( ) & str. showbase 가 0이 아닌 경우( std::showbase 조작자가 사용된 경우), 통화 기호나 문자열은 mp. curr_symbol ( ) 를 호출하여 생성되며, 출력 시퀀스에서 symbol 이 포맷팅 패턴에 나타나는 위치에 배치됩니다.
만약 mp. positive_sign ( ) (양수 형식 패턴이 사용되는 경우) 또는 mp. negative_sign ( ) (음수 형식 패턴이 사용되는 경우)가 둘 이상의 문자를 가진 문자열을 반환하면, 반환된 첫 번째 문자는 서식 패턴에서 sign 이 나타나는 위치에 배치되고, 나머지 문자들은 다른 모든 문자 뒤에 배치됩니다. 예를 들어, 서식 패턴 { sign, value, space, symbol } 에 단위 123 과 "-" 의 negative_sign을 사용하면 "-1.23 €" 가 될 수 있는 반면, "()" 의 negative_sign은 "(1.23 €)" 를 생성할 수 있습니다.
지정된 형식에 대해 생성된 문자 수가 str. width ( ) 에서 반환된 값보다 적은 경우, 출력 시퀀스의 총 길이를 정확히 str. width ( ) 로 만들기 위해 fill 의 복사본이 다음과 같이 삽입됩니다:
-
만약
str.
flags
(
)
&
str.
adjustfield
이
str.
internal
와 같다면, 채움 문자들은 서식 패턴에서
none또는space가 나타나는 위치에 삽입됩니다. - 그렇지 않고 만약 str. flags ( ) & str. adjustfield 이 str. left 와 같다면, fill 의 복사본들이 다른 모든 문자 뒤에 추가됩니다.
- 그 외의 경우, 채움 문자들은 다른 모든 문자 앞에 배치됩니다.
결국, str. width ( 0 ) 를 호출하여 std::setw 의 효과를 취소합니다.
목차 |
반환값
생성된 마지막 문자 바로 다음을 가리키는 반복자.
참고 사항
통화 단위는 통화의 가장 작은 비분할 단위로 가정됩니다: 미국에서는 센트, 일본에서는 엔.
예제
#include <iomanip> #include <iostream> #include <locale> struct my_punct : std::moneypunct_byname<char, false> { my_punct(const char* name) : moneypunct_byname(name) {} string_type do_negative_sign() const { return "()"; } }; int main() { std::locale loc("ru_RU.utf8"); std::cout.imbue(loc); long double units = -123.45; std::cout << "In Russian locale, " << units << " prints as " << std::showbase; // note, the following is equivalent to simply std::put_money(units) std::use_facet<std::money_put<char>>(loc).put( {std::cout}, false, std::cout, std::cout.fill(), units); std::cout << '\n'; std::cout.imbue(std::locale(std::cout.getloc(), new my_punct("ru_RU.utf8"))); std::cout << "With negative_sign set to \"()\", it prints as "; std::use_facet<std::money_put<char>>(loc).put( {std::cout}, false, std::cout, std::cout.fill(), units); std::cout << '\n'; }
출력:
In Russian locale, -123,45 prints as -1.23 руб With negative_sign set to "()", it prints as (1.23 руб)
결함 보고서
다음의 동작 변경 결함 보고서들은 이전에 발표된 C++ 표준에 소급 적용되었습니다.
| DR | 적용 대상 | 게시된 동작 | 올바른 동작 |
|---|---|---|---|
| LWG 328 | C++98 | std::sprintf 에 사용된 형식 문자열이 "%.01f" 였음 | "%.0Lf" 로 수정됨 |
참고 항목
|
std::money_get
과
std::money_put
에서 사용되는 통화 서식 매개변수를 정의합니다
(클래스 템플릿) |
|
|
입력 문자 시퀀스에서 통화 값을 구문 분석하고 구성합니다
(클래스 템플릿) |
|
|
(C++11)
|
통화 값을 서식화하고 출력합니다
(함수 템플릿) |