std::numpunct<CharT>:: grouping, std::numpunct<CharT>:: do_grouping
| Localization library | |||||||||||||||||||||||||
| Regular expressions library (C++11) | |||||||||||||||||||||||||
| Formatting library (C++20) | |||||||||||||||||||||||||
| Null-terminated sequence utilities | |||||||||||||||||||||||||
| Byte strings | |||||||||||||||||||||||||
| Multibyte strings | |||||||||||||||||||||||||
| Wide strings | |||||||||||||||||||||||||
| Primitive numeric conversions | |||||||||||||||||||||||||
|
|||||||||||||||||||||||||
| Text encoding identifications | |||||||||||||||||||||||||
|
|||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Member functions | ||||
|
numpunct::grouping
numpunct::do_grouping
|
||||
|
헤더 파일에 정의됨
<locale>
|
||
|
public
:
std:: string grouping ( ) const ; |
(1) | |
|
protected
:
virtual std:: string do_grouping ( ) const ; |
(2) | |
do_grouping
멤버 함수를 호출합니다.
이 함수는 정수 값들의 벡터로 사용되는 문자열,
vec
를 반환합니다. (예를 들어,
"
\003
"
는 각각 3자리씩의 그룹을 지정하는 반면,
"3"
는 각각 51자리씩의 그룹을 의미합니다.). 각 요소
vec
[
i
]
는 숫자의 정수 부분에서 오른쪽부터 세어
i
번째 자리 그룹의 자릿수를 나타냅니다:
vec
[
0
]
는 가장 오른쪽 그룹의 자릿수를,
vec
[
1
]
는 오른쪽에서 두 번째 그룹의 자릿수를 보유합니다. 마지막 문자,
vec
[
vec.
size
(
)
-
1
]
로 표시된 그룹화는 숫자의 (왼쪽 부분에) 남은 모든 자릿수를 그룹화하기 위해 반복적으로 재사용됩니다. 만약
vec
[
i
]
가 양수가 아니거나
CHAR_MAX
와 같다면 해당 자리 그룹의 크기는 무제한입니다.
반환값
그룹을 담고 있는
std::string
타입의 객체입니다.
std::numpunct
의 표준 특수화들은 빈 문자열을 반환하며, 이는 그룹화가 없음을 의미합니다. 일반적인 그룹화(예:
en_US
로케일)는
"
\003
"
을 반환합니다.
예제
#include <iostream> #include <limits> #include <locale> struct space_out : std::numpunct<char> { char do_thousands_sep() const { return ' '; } // 공백으로 구분 std::string do_grouping() const { return "\1"; } // 1자리씩 그룹화 }; struct g123 : std::numpunct<char> { std::string do_grouping() const { return "\1\2\3"; } }; int main() { std::cout << "Default locale: " << 12345678 << '\n'; std::cout.imbue(std::locale(std::cout.getloc(), new space_out)); std::cout << "Locale with modified numpunct: " << 12345678 << '\n'; std::cout.imbue(std::locale(std::cout.getloc(), new g123)); std::cout << "Locale with \\1\\2\\3 grouping: " << std::numeric_limits<unsigned long long>::max() << '\n' << "Same, for a floating-point number: " << std::fixed << 123456789.123456789 << '\n'; }
출력:
Default locale: 12345678 Locale with modified numpunct: 1 2 3 4 5 6 7 8 Locale with \1\2\3 grouping: 18,446,744,073,709,551,61,5 Same, for a floating-point number: 123,456,78,9.123457
참고 항목
|
[virtual]
|
천 단위 구분자로 사용할 문자를 제공함
(가상 protected 멤버 함수) |