moneypunct 类
一种类模板,用于描述一个对象来充当区域设置 facet,以便描述用来表示货币输入字段或货币输出字段的 CharType 类型的序列。 如果模板参数 Intl 为 true,则遵循国际约定。
语法
template <class CharType, bool Intl>
class moneypunct;
参数
CharType
在程序中用于对字符进行编码的类型。
Intl
一种用于指定是否遵守国际约定的标志。
备注
对于任何区域设置 facet,静态对象 ID 的初始存储值为零。 首次尝试访问其存储值后,将在 ID 中存储唯一正值。
常量静态对象 intl 用于存储模板参数 Intl 的值。
构造函数
构造函数 | 说明 |
---|---|
moneypunct | moneypunct 类型对象的构造函数。 |
Typedef
类型名称 | 说明 |
---|---|
char_type | 一种类型,此类型用于描述区域设置使用的字符。 |
string_type | 一种类型,此类型描述包含 CharType 类型字符的字符串。 |
成员函数
成员函数 | 说明 |
---|---|
curr_symbol | 返回要用作货币符号的区域设置特定元素序列。 |
decimal_point | 返回要用作小数点符号的区域设置特定元素序列。 |
do_curr_symbol | 一种受保护的虚拟成员函数,可返回要用作货币符号的区域设置特定元素序列。 |
do_decimal_point | 一种受保护的虚拟成员函数,通过调用此函数可返回要用作小数点符号的区域设置特定元素序列。 |
do_frac_digits | 此受保护的虚拟成员函数可返回一个在任何小数点右侧显示的位数计数。 |
do_grouping | 此受保护的虚拟成员函数可返回一个区域设置特定规则,用于确定如何对任何小数点左侧的数字进行分组。 |
do_neg_format | 一种受保护的虚拟成员函数,通过调用此函数可返回一个区域设置特定规则,用于对包含负数的输出结果进行格式化。 |
do_negative_sign | 一种受保护的虚拟成员函数,通过调用此函数可返回要用作负号符号的区域设置特定元素序列。 |
do_pos_format | 一种受保护的虚拟成员函数,通过调用此函数可返回一个区域设置特定规则,用于对包含正数的输出结果进行格式化。 |
do_positive_sign | 一种受保护的虚拟成员函数,通过调用此函数可返回要用作正号符号的区域设置特定元素序列。 |
do_thousands_sep | 一种受保护的虚拟成员函数,通过调用此函数可返回要用作千位分隔符号的区域设置特定元素序列。 |
frac_digits | 可返回一个在任何小数点右侧显示的位数计数。 |
grouping | 返回用于确定位数如何分组到任何小数点左边的区域设置特定规则。 |
neg_format | 返回一个区域设置特定规则,用于对包含负数的输出结果进行格式化。 |
negative_sign | 返回要用作负号符号的区域设置特定元素序列。 |
pos_format | 返回一个区域设置特定规则,用于对包含正数的输出结果进行格式化。 |
positive_sign | 返回要用作正号符号的区域设置特定元素序列。 |
thousands_sep | 返回要用作千位分隔符号的区域设置特定元素序列。 |
要求
标头:<locale>
命名空间: std
moneypunct::char_type
一种类型,此类型用于描述区域设置使用的字符。
typedef CharType char_type;
备注
该类型是模板参数 CharType 的同义词。
moneypunct::curr_symbol
返回要用作货币符号的区域设置特定元素序列。
string_type curr_symbol() const;
返回值
包含货币符号的字符串。
备注
此成员函数返回 do_curr_symbol。
示例
// moneypunct_curr_symbol.cpp
// compile with: /EHsc
#include <locale>
#include <iostream>
#include <sstream>
using namespace std;
int main( )
{
locale loc( "german_germany" );
const moneypunct < char, true > &mpunct = use_facet < moneypunct < char, true > >(loc);
cout << loc.name( ) << " international currency symbol "<< mpunct.curr_symbol( ) << endl;
const moneypunct < char, false> &mpunct2 = use_facet < moneypunct < char, false> >(loc);
cout << loc.name( ) << " domestic currency symbol "<< mpunct2.curr_symbol( ) << endl;
};
moneypunct::decimal_point
返回要用作小数点符号的区域设置特定元素序列。
CharType decimal_point() const;
返回值
要用作小数点符号的区域设置特定元素序列。
注解
此成员函数返回 do_decimal_point。
示例
// moneypunct_decimal_pt.cpp
// compile with: /EHsc
#include <locale>
#include <iostream>
#include <sstream>
using namespace std;
int main( )
{
locale loc("german_germany");
const moneypunct < char, true > &mpunct = use_facet
< moneypunct < char, true > >(loc);
cout << loc.name( ) << " international decimal point "
<< mpunct.decimal_point( ) << endl;
const moneypunct < char, false> &mpunct2 = use_facet
< moneypunct < char, false> >(loc);
cout << loc.name( ) << " domestic decimal point "
<< mpunct2.decimal_point( ) << endl;
}
German_Germany.1252 international decimal point ,
German_Germany.1252 domestic decimal point ,
moneypunct::do_curr_symbol
一种受保护的虚拟成员函数,可返回要用作货币符号的区域设置特定元素序列。
virtual string_type do_curr_symbol() const;
返回值
要用作小数点符号的区域设置特定元素序列。
示例
请参阅 curr_symbol 的示例,其中虚拟成员函数由 curr_symbol
调用。
moneypunct::do_decimal_point
一种受保护的虚拟成员函数,可返回要用作小数点符号的区域设置特定元素序列。
virtual CharType do_decimal_point() const;
返回值
要用作小数点符号的区域设置特定元素序列。
示例
请参阅 decimal_point 的示例,其中虚拟成员函数由 decimal_point
调用。
moneypunct::do_frac_digits
一种受保护的虚拟成员函数,可返回一个在任何小数点右侧显示的位数计数。
virtual int do_frac_digits() const;
返回值
一个在任何小数点右侧显示的区域设置特定位数计数。
示例
请参阅 frac_digits 的示例,其中虚拟成员函数由 frac_digits
调用。
moneypunct::do_grouping
一种受保护的虚拟成员函数,可返回用于确定如何对任何小数点左侧的数字进行分组的区域设置特定规则。
virtual string do_grouping() const;
返回值
用于确定如何对任何小数点左侧的数字进行分组的区域设置特定规则。
示例
请参阅 grouping 的示例,其中虚拟成员函数由 grouping
调用。
moneypunct::do_neg_format
一种受保护的虚拟成员函数,通过调用此函数可返回一个区域设置特定规则,用于对包含负数的输出结果进行格式化。
virtual pattern do_neg_format() const;
返回值
此受保护的虚拟成员函数可返回一个区域设置特定规则,用于确定生成负金额的货币输出字段的方式。 pattern::field
的四个元素中的每一个都可以具有以下值:
none
,用于匹配零个或多个空格,或不生成任何内容。sign
,用于匹配或生成正负号。space
,用于匹配零个或多个空格,或生成一个空格。symbol
,用于匹配或生成货币符号。value
,用于匹配或生成货币值。
生成货币输出字段组件和匹配货币输入字段组件都以这些元素在 pattern::field
中显示的顺序进行。 sign
、symbol
、value
以及 none
或 space
中的每个值必须只出现一次。 值 none
不能第一个出现。 值 space
不能第一个或最后一个出现。 如果 Intl
为 true,则顺序为 symbol
、sign
、none
,然后是 value
。
模板版本的 moneypunct< CharType, Intl >
返回 {money_base::symbol, money_base::sign, money_base::value, money_base::none}
。
示例
请参阅 neg_format 的示例,其中虚拟成员函数由 neg_format
调用。
moneypunct::do_negative_sign
一种受保护的虚拟成员函数,通过调用此函数可返回要用作负号符号的区域设置特定元素序列。
virtual string_type do_negative_sign() const;
返回值
要用作负号的区域设置特定元素序列。
示例
请参阅 negative_sign 的示例,其中虚拟成员函数由 negative_sign
调用。
moneypunct::do_pos_format
一种受保护的虚拟成员函数,通过调用此函数可返回一个区域设置特定规则,用于对包含正数的输出结果进行格式化。
virtual pattern do_pos_format() const;
返回值
此受保护的虚拟成员函数可返回一个区域设置特定规则,用于确定生成正金额的货币输出字段的方式。 (它还确定如何匹配货币输入字段的组件。)编码与 do_neg_format 相同。
模板版本的 moneypunct< CharType, Inputlterator >
返回 { money_base::symbol, money_base::sign, money_base::value, money_base::none }
。
示例
请参阅 pos_format 的示例,其中虚拟成员函数由 pos_format
调用。
moneypunct::do_positive_sign
一种受保护的虚拟成员函数,可返回要用作正号的区域设置特定元素序列。
virtual string_type do_positive_sign() const;
返回值
要用作正号的区域设置特定元素序列。
示例
请参阅 positive_sign 的示例,其中虚拟成员函数由 positive_sign
调用。
moneypunct::do_thousands_sep
一种受保护的虚拟成员函数,可返回要用作任何小数点左侧的组分隔符的区域设置特定元素。
virtual CharType do_thousands_sep() const;
返回值
要用作任何小数点左侧的组分隔符的区域设置特定元素。
示例
请参阅 thousands_sep 的示例,其中虚拟成员函数由 thousands_sep
调用。
moneypunct::frac_digits
可返回一个在任何小数点右侧显示的位数计数。
int frac_digits() const;
返回值
一个在任何小数点右侧显示的区域设置特定位数计数。
注解
此成员函数返回 do_frac_digits。
示例
// moneypunct_frac_digits.cpp
// compile with: /EHsc
#include <locale>
#include <iostream>
#include <sstream>
using namespace std;
int main( )
{
locale loc( "german_germany" );
const moneypunct <char, true> &mpunct =
use_facet <moneypunct <char, true> >(loc);
for (unsigned int i = 0; i <mpunct.grouping( ).length( ); i++ )
{
cout << loc.name( ) << " international grouping:\n the "
<< i <<"th group to the left of the radix character "
<< "is of size " << (int)(mpunct.grouping ( )[i])
<< endl;
}
cout << loc.name( ) << " international frac_digits\n to the right"
<< " of the radix character: "
<< mpunct.frac_digits ( ) << endl << endl;
const moneypunct <char, false> &mpunct2 =
use_facet <moneypunct <char, false> >(loc);
for (unsigned int i = 0; i <mpunct2.grouping( ).length( ); i++ )
{
cout << loc.name( ) << " domestic grouping:\n the "
<< i <<"th group to the left of the radix character "
<< "is of size " << (int)(mpunct2.grouping ( )[i])
<< endl;
}
cout << loc.name( ) << " domestic frac_digits\n to the right"
<< " of the radix character: "
<< mpunct2.frac_digits ( ) << endl << endl;
}
German_Germany.1252 international grouping:
the 0th group to the left of the radix character is of size 3
German_Germany.1252 international frac_digits
to the right of the radix character: 2
German_Germany.1252 domestic grouping:
the 0th group to the left of the radix character is of size 3
German_Germany.1252 domestic frac_digits
to the right of the radix character: 2
moneypunct::grouping
返回用于确定位数如何分组到任何小数点左边的区域设置特定规则。
string grouping() const;
返回值
用于确定如何对任何小数点左侧的数字进行分组的区域设置特定规则。
备注
此成员函数返回 do_grouping。
示例
// moneypunct_grouping.cpp
// compile with: /EHsc
#include <locale>
#include <iostream>
#include <sstream>
using namespace std;
int main( )
{
locale loc( "german_germany" );
const moneypunct <char, true> &mpunct =
use_facet <moneypunct <char, true> >( loc );
for (unsigned int i = 0; i <mpunct.grouping( ).length( ); i++ )
{
cout << loc.name( ) << " international grouping:\n the "
<< i <<"th group to the left of the radix character "
<< "is of size " << (int)(mpunct.grouping ( )[i])
<< endl;
}
cout << loc.name( ) << " international frac_digits\n to the right"
<< " of the radix character: "
<< mpunct.frac_digits ( ) << endl << endl;
const moneypunct <char, false> &mpunct2 =
use_facet <moneypunct <char, false> >( loc );
for (unsigned int i = 0; i <mpunct2.grouping( ).length( ); i++ )
{
cout << loc.name( ) << " domestic grouping:\n the "
<< i <<"th group to the left of the radix character "
<< "is of size " << (int)(mpunct2.grouping ( )[i])
<< endl;
}
cout << loc.name( ) << " domestic frac_digits\n to the right"
<< " of the radix character: "
<< mpunct2.frac_digits ( ) << endl << endl;
}
German_Germany.1252 international grouping:
the 0th group to the left of the radix character is of size 3
German_Germany.1252 international frac_digits
to the right of the radix character: 2
German_Germany.1252 domestic grouping:
the 0th group to the left of the radix character is of size 3
German_Germany.1252 domestic frac_digits
to the right of the radix character: 2
moneypunct::moneypunct
moneypunct
类型对象的构造函数。
explicit moneypunct(size_t _Refs = 0);
参数
_Refs
用于指定对象的内存管理类型的整数值。
备注
_Refs 参数可能的值及其含义:
0:对象的生存期由包含该对象的区域设置管理。
1:必须手动管理对象的生存期。
> 1:未定义这些值。
由于该析构函数受到保护,可能没有直接的示例。
构造函数通过 locale::facet(_ Refs) 初始化其基对象。
moneypunct::neg_format
返回一个区域设置特定规则,用于对包含负数的输出结果进行格式化。
pattern neg_format() const;
返回值
用于格式化包含负数的输出结果的区域设置特定规则。
备注
此成员函数返回 do_neg_format。
示例
// moneypunct_neg_format.cpp
// compile with: /EHsc
#include <locale>
#include <iostream>
#include <sstream>
using namespace std;
int main( ) {
locale loc( "german_germany" );
const moneypunct <char, true> &mpunct =
use_facet <moneypunct <char, true > >(loc);
cout << loc.name( ) << " international negative number format: "
<< mpunct.neg_format( ).field[0]
<< mpunct.neg_format( ).field[1]
<< mpunct.neg_format( ).field[2]
<< mpunct.neg_format( ).field[3] << endl;
const moneypunct <char, false> &mpunct2 =
use_facet <moneypunct <char, false> >(loc);
cout << loc.name( ) << " domestic negative number format: "
<< mpunct2.neg_format( ).field[0]
<< mpunct2.neg_format( ).field[1]
<< mpunct2.neg_format( ).field[2]
<< mpunct2.neg_format( ).field[3] << endl;
}
moneypunct::negative_sign
返回要用作负号符号的区域设置特定元素序列。
string_type negative_sign() const;
返回值
返回要用作负号符号的区域设置特定元素序列。
注解
此成员函数返回 do_negative_sign。
示例
// moneypunct_neg_sign.cpp
// compile with: /EHsc
#include <locale>
#include <iostream>
#include <sstream>
using namespace std;
int main( )
{
locale loc( "german_germany" );
const moneypunct <char, true> &mpunct =
use_facet <moneypunct <char, true> >(loc);
cout << loc.name( ) << " international negative sign: "
<< mpunct.negative_sign( ) << endl;
const moneypunct <char, false> &mpunct2 =
use_facet <moneypunct <char, false> >(loc);
cout << loc.name( ) << " domestic negative sign: "
<< mpunct2.negative_sign( ) << endl;
locale loc2( "French" );
const moneypunct <char, true> &mpunct3 =
use_facet <moneypunct <char, true> >(loc2);
cout << loc2.name( ) << " international negative sign: "
<< mpunct3.negative_sign( ) << endl;
const moneypunct <char, false> &mpunct4 =
use_facet <moneypunct <char, false> >(loc2);
cout << loc2.name( ) << " domestic negative sign: "
<< mpunct4.negative_sign( ) << endl;
};
German_Germany.1252 international negative sign: -
German_Germany.1252 domestic negative sign: -
French_France.1252 international negative sign: -
French_France.1252 domestic negative sign: -
moneypunct::pos_format
返回一个区域设置特定规则,用于对包含正数的输出结果进行格式化。
pattern pos_format() const;
返回值
用于格式化包含正数的输出结果的区域设置特定规则。
备注
此成员函数返回 do_pos_format。
示例
// moneypunct_pos_format.cpp
// compile with: /EHsc
#include <locale>
#include <iostream>
#include <sstream>
using namespace std;
int main() {
locale loc( "german_germany" );
const moneypunct <char, true> &mpunct =
use_facet <moneypunct <char, true> >(loc);
cout << loc.name( ) << " international positive number format: "
<< mpunct.pos_format( ).field[0]
<< mpunct.pos_format( ).field[1]
<< mpunct.pos_format( ).field[2]
<< mpunct.pos_format( ).field[3] << endl;
const moneypunct <char, false> &mpunct2 =
use_facet <moneypunct <char, false> >(loc);
cout << loc.name( ) << " domestic positive number format: "
<< mpunct2.pos_format( ).field[0]
<< mpunct2.pos_format( ).field[1]
<< mpunct2.pos_format( ).field[2]
<< mpunct2.pos_format( ).field[3] << endl;
}
moneypunct::positive_sign
返回要用作正号符号的区域设置特定元素序列。
string_type positive_sign() const;
返回值
要用作正号符号的区域设置特定元素序列。
备注
此成员函数返回 do_positive_sign。
示例
// moneypunct_pos_sign.cpp
// compile with: /EHsc
#include <locale>
#include <iostream>
#include <sstream>
using namespace std;
int main( )
{
locale loc( "german_germany" );
const moneypunct <char, true> &mpunct =
use_facet <moneypunct <char, true > >(loc);
cout << loc.name( ) << " international positive sign:"
<< mpunct.positive_sign( ) << endl;
const moneypunct <char, false> &mpunct2 =
use_facet <moneypunct <char, false> >(loc);
cout << loc.name( ) << " domestic positive sign:"
<< mpunct2.positive_sign( ) << endl;
locale loc2( "French" );
const moneypunct <char, true> &mpunct3 =
use_facet <moneypunct <char, true> >(loc2);
cout << loc2.name( ) << " international positive sign:"
<< mpunct3.positive_sign( ) << endl;
const moneypunct <char, false> &mpunct4 =
use_facet <moneypunct <char, false> >(loc2);
cout << loc2.name( ) << " domestic positive sign:"
<< mpunct4.positive_sign( ) << endl;
};
German_Germany.1252 international positive sign:
German_Germany.1252 domestic positive sign:
French_France.1252 international positive sign:
French_France.1252 domestic positive sign:
moneypunct::string_type
一种类型,此类型描述包含 CharType 类型字符的字符串。
typedef basic_string<CharType, Traits, Allocator> string_type;
备注
此类型描述 basic_string 类模板的专用化,该类模板的对象可存储标点序列的副本。
moneypunct::thousands_sep
返回要用作千位分隔符号的区域设置特定元素序列。
CharType thousands_sep() const;
返回值
要用作千位分隔符的区域设置特定元素序列
备注
此成员函数返回 do_thousands_sep。
示例
// moneypunct_thou_sep.cpp
// compile with: /EHsc
#include <locale>
#include <iostream>
#include <sstream>
using namespace std;
int main( )
{
locale loc( "german_germany" );
const moneypunct <char, true> &mpunct =
use_facet <moneypunct <char, true > >(loc);
cout << loc.name( ) << " international thousands separator: "
<< mpunct.thousands_sep( ) << endl;
const moneypunct <char, false> &mpunct2 =
use_facet <moneypunct <char, false> >(loc);
cout << loc.name( ) << " domestic thousands separator: "
<< mpunct2.thousands_sep( ) << endl << endl;
locale loc2( "english_canada" );
const moneypunct <char, true> &mpunct3 =
use_facet <moneypunct <char, true> >(loc2);
cout << loc2.name( ) << " international thousands separator: "
<< mpunct3.thousands_sep( ) << endl;
const moneypunct <char, false> &mpunct4 =
use_facet <moneypunct <char, false> >(loc2);
cout << loc2.name( ) << " domestic thousands separator: "
<< mpunct4.thousands_sep( ) << endl;
}
German_Germany.1252 international thousands separator: .
German_Germany.1252 domestic thousands separator: .
English_Canada.1252 international thousands separator: ,
English_Canada.1252 domestic thousands separator: ,
另请参阅
反馈
https://aka.ms/ContentUserFeedback。
即将发布:在整个 2024 年,我们将逐步淘汰作为内容反馈机制的“GitHub 问题”,并将其取代为新的反馈系统。 有关详细信息,请参阅:提交和查看相关反馈