description | title | ms.date | f1_keywords | helpviewer_keywords | ms.assetid | ||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Learn more about: numpunct Class |
numpunct Class |
11/04/2016 |
|
|
73fb93cc-ac11-4c98-987c-bfa6267df596 |
A class template that describes an object that can serve as a local facet to describe the sequences of type CharType
used to represent information about the formatting and punctuation of numeric and Boolean expressions.
template <class CharType>
class numpunct : public locale::facet;
CharType
The type used within a program to encode characters in a locale.
As with any locale facet, the static object ID has an initial stored value of zero. The first attempt to access its stored value stores a unique positive value in id.
Constructor | Description |
---|---|
numpunct | The constructor for objects of type numpunct . |
Type name | Description |
---|---|
char_type | A type that is used to describe a character used by a locale. |
string_type | A type that describes a string containing characters of type CharType . |
Member function | Description |
---|---|
decimal_point | Returns a locale-specific element to use as a decimal point. |
do_decimal_point | A protected virtual member function that is called to return a locale-specific element to use as a decimal point. |
do_falsename | A protected virtual member function that is called to return a string to use as a text representation of the value false . |
do_grouping | A protected virtual member function that is called to return a locale-specific rule for determining how digits are grouped to the left of any decimal point. |
do_thousands_sep | A protected virtual member function that is called to return a locale-specific element to use as a thousands separator. |
do_truename | A protected virtual member function that is called to return a string to use as a text representation of the value true . |
falsename | Returns a string to use as a text representation of the value false . |
grouping | Returns a locale-specific rule for determining how digits are grouped to the left of any decimal point. |
thousands_sep | Returns a locale-specific element to use as a thousands separator. |
truename | Returns a string to use as a text representation of the value true . |
Header: <locale>
Namespace: std
A type that is used to describe a character used by a locale.
typedef CharType char_type;
The type is a synonym for the template parameter CharType.
Returns a locale-specific element to use as a decimal point.
CharType decimal_point() const;
A locale-specific element to use as a decimal point.
The member function returns do_decimal_point.
// numpunct_decimal_point.cpp
// compile with: /EHsc
#include <locale>
#include <iostream>
#include <sstream>
using namespace std;
int main( )
{
locale loc( "german_germany" );
const numpunct <char> &npunct =
use_facet <numpunct <char> >( loc);
cout << loc.name( ) << " decimal point "<<
npunct.decimal_point( ) << endl;
cout << loc.name( ) << " thousands separator "
<< npunct.thousands_sep( ) << endl;
};
German_Germany.1252 decimal point ,
German_Germany.1252 thousands separator .
A protected virtual member function that is called to return a locale-specific element to use as a decimal point.
virtual CharType do_decimal_point() const;
A locale-specific element to use as a decimal point.
See the example for decimal_point, where the virtual member function is called by decimal_point
.
The protected virtual member function returns a sequence to use as a text representation of the value false
.
virtual string_type do_falsename() const;
A string containing a sequence to use as a text representation of the value false
.
The member function returns the string "false" to represent the value false
in all locales.
See the example for falsename, where the virtual member function is called by falsename
.
A protected virtual member function that is called to return a locale-specific rule for determining how digits are grouped to the left of any decimal point.
virtual string do_grouping() const;
A locale-specific rule for determining how digits are grouped to the left of any decimal point.
The protected virtual member function returns a locale-specific rule for determining how digits are grouped to the left of any decimal point. The encoding is the same as for lconv::grouping.
See the example for grouping, where the virtual member function is called by grouping
.
A protected virtual member function that is called to return a locale-specific element to use as a thousands separator.
virtual CharType do_thousands_sep() const;
Returns a locale-specific element to use as a thousands separator.
The protected virtual member function returns a locale-specific element of type CharType
to use as a group separator to the left of any decimal point.
See the example for thousands_sep, where the virtual member function is called by thousands_sep
.
A protected virtual member function that is called to return a string to use as a text representation of the value true
.
virtual string_type do_truename() const;
A string to use as a text representation of the value true
.
All locales return a string "true" to represent the value true
.
See the example for truename, where the virtual member function is called by truename
.
Returns a string to use as a text representation of the value false
.
string_type falsename() const;
A string containing a sequence of CharType
s to use as a text representation of the value false
.
The member function returns the string "false" to represent the value false
in all locales.
The member function returns do_falsename.
// numpunct_falsename.cpp
// compile with: /EHsc
#include <locale>
#include <iostream>
#include <sstream>
using namespace std;
int main( )
{
locale loc( "English" );
const numpunct <char> &npunct = use_facet <numpunct <char> >( loc );
cout << loc.name( ) << " truename "<< npunct.truename( ) << endl;
cout << loc.name( ) << " falsename "<< npunct.falsename( ) << endl;
locale loc2( "French" );
const numpunct <char> &npunct2 = use_facet <numpunct <char> >(loc2);
cout << loc2.name( ) << " truename "<< npunct2.truename( ) << endl;
cout << loc2.name( ) << " falsename "<< npunct2.falsename( ) << endl;
}
English_United States.1252 truename true
English_United States.1252 falsename false
French_France.1252 truename true
French_France.1252 falsename false
Returns a locale-specific rule for determining how digits are grouped to the left of any decimal point.
string grouping() const;
A locale-specific rule for determining how digits are grouped to the left of any decimal point.
The member function returns do_grouping.
// numpunct_grouping.cpp
// compile with: /EHsc
#include <locale>
#include <iostream>
#include <sstream>
using namespace std;
int main( )
{
locale loc( "german_germany");
const numpunct <char> &npunct =
use_facet < numpunct <char> >( loc );
for (unsigned int i = 0; i < npunct.grouping( ).length( ); i++)
{
cout << loc.name( ) << " international grouping:\n the "
<< i <<"th group to the left of the radix character "
<< "is of size " << (int)(npunct.grouping ( )[i])
<< endl;
}
}
German_Germany.1252 international grouping:
the 0th group to the left of the radix character is of size 3
The constructor for objects of type numpunct
.
explicit numpunct(size_t _Refs = 0);
_Refs
Integer value used to specify the type of memory management for the object.
The possible values for the _Refs parameter and their significance are:
-
0: The lifetime of the object is managed by the locales that contain it.
-
1: The lifetime of the object must be manually managed.
-
> 1: These values are not defined.
No direct examples are possible, because the destructor is protected.
The constructor initializes its base object with locale::facet(_Refs
).
A type that describes a string containing characters of type CharType.
typedef basic_string<CharType, Traits, Allocator> string_type;
The type describes a specialization of class template basic_string whose objects can store copies of the punctuation sequences.
Returns a locale-specific element to use as a thousands separator.
CharType thousands_sep() const;
A locale-specific element to use as a thousands separator.
The member function returns do_thousands_sep.
// numpunct_thou_sep.cpp
// compile with: /EHsc
#include <locale>
#include <iostream>
#include <sstream>
using namespace std;
int main( )
{
locale loc( "german_germany" );
const numpunct <char> &npunct =
use_facet < numpunct < char > >( loc );
cout << loc.name( ) << " decimal point "<<
npunct.decimal_point( ) << endl;
cout << loc.name( ) << " thousands separator "
<< npunct.thousands_sep( ) << endl;
};
German_Germany.1252 decimal point ,
German_Germany.1252 thousands separator .
Returns a string to use as a text representation of the value true
.
string_type falsename() const;
A string to use as a text representation of the value true
.
The member function returns do_truename.
All locales return a string "true" to represent the value true
.
// numpunct_truename.cpp
// compile with: /EHsc
#include <locale>
#include <iostream>
#include <sstream>
using namespace std;
int main( )
{
locale loc( "English" );
const numpunct < char> &npunct = use_facet <numpunct <char> >( loc );
cout << loc.name( ) << " truename "<< npunct.truename( ) << endl;
cout << loc.name( ) << " falsename "<< npunct.falsename( ) << endl;
locale loc2("French");
const numpunct <char> &npunct2 = use_facet <numpunct <char> >( loc2 );
cout << loc2.name( ) << " truename "<< npunct2.truename( ) << endl;
cout << loc2.name( ) << " falsename "<< npunct2.falsename( ) << endl;
}
English_United States.1252 truename true
English_United States.1252 falsename false
French_France.1252 truename true
French_France.1252 falsename false
<locale>
facet Class
Thread Safety in the C++ Standard Library