Skip site navigation (1)Skip section navigation (2)

FreeBSD Manual Pages

  
 
  

home | help
std::numpunct(3)	      C++ Standard Libary	      std::numpunct(3)

NAME
       std::numpunct - std::numpunct

Synopsis
	  Defined in header <locale>
	  template< class CharT	>
	  class	numpunct;

	  The  facet  std::numpunct  encapsulates  numeric punctuation prefer-
       ences. Stream I/O
	  operations use std::numpunct through std::num_get  and  std::num_put
       for parsing
	  numeric input	and formatting numeric output.

	  The  numbers that are	supported by std::numpunct have	the format de-
       scribed below.
	  Here digit represents	the radix set specified	by the fmtflags	 argu-
       ment value,
	  thousands-sep	 and  decimal-point are	the results of thousands_sep()
       and
	  decimal_point() functions respectively. The format of	integer	values
       is as follows:

	integer	    ::=	[sign] units
	sign	    ::=	plusminus
	plusminus   ::=	'+' | '-'
	units	    ::=	digits [thousands-sep units]
	digits	    ::=	digit [digits]

	  The number of	digits between the thousand-seps (maximum size of dig-
       its) is specified
	  by the result	of grouping().

	  The format of	floating-point values is as follows:

	floatval    ::=	[sign] units [decimal-point [digits]] [e  [sign]  dig-
       its] |
			[sign]	       decimal-point   digits	[e [sign] dig-
       its]
	e	    ::=	'e' | 'E'

	  std-numpunct-inheritance.svg

					  Inheritance diagram

	  Two standalone (locale-independent) specializations are provided  by
       the standard
	  library:

	  Defined in header <locale>
	  std::numpunct<char>	  provides equivalents of the "C" locale pref-
       erences
	  std::numpunct<wchar_t> provides wide character  equivalents  of  the
       "C" locale
				 preferences

	  In addition, every locale object constructed in a C++	program	imple-
       ments its own
	  (locale-specific) versions of	these specializations.

Member types
	  Member type Definition
	  char_type   charT
	  string_type std::basic_string<charT>

Member functions
	  constructor	constructs a new numpunct facet
			(public	member function)
	  destructor	destructs a numpunct facet
			(protected member function)
	  decimal_point	invokes	do_decimal_point
			(public	member function)
	  thousands_sep	invokes	do_thousands_sep
			(public	member function)
	  grouping	invokes	do_grouping
			(public	member function)
	  truename	invokes	do_truename or do_falsename
	  falsename	(public	member function)

Protected member functions
	  do_decimal_point provides the	character to use as decimal point
	  [virtual]	   (virtual protected member function)
	  do_thousands_sep  provides the character to use as thousands separa-
       tor
	  [virtual]	   (virtual protected member function)
	  do_grouping	   provides the	numbers	of digits between each pair of
       thousands
	  [virtual]	   separators
			   (virtual protected member function)
	  do_truename	   provides the	string to  use	as  the	 name  of  the
       boolean true and
	  do_falsename	   false
	  [virtual]	   (virtual protected member function)

Member objects
	  static std::locale::id id id of the locale
				    (public member object)

Example
	  The following	example	changes	the string representations of true and
       false

       // Run this code

	#include <iostream>
	#include <locale>

	struct french_bool : std::numpunct<char> {
	    string_type	do_truename() const override { return "vrai"; }
	    string_type	do_falsename() const override {	return "faux"; }
	};

	int main()
	{
	    std::cout << "default locale: "
		      << std::boolalpha	<< true	<< ", "	<< false << '\n';
	    std::cout.imbue(std::locale(std::cout.getloc(), new	french_bool));
	    std::cout << "locale with modified numpunct: "
		      << std::boolalpha	<< true	<< ", "	<< false << '\n';
	}

Output:
	default	locale:	true, false
	locale with modified numpunct: vrai, faux

See also
	  numpunct_byname creates a numpunct facet for the named locale
			  (class template)

http://cppreference.com		  2022.07.31		      std::numpunct(3)

Want to link to this manual page? Use this URL:
<https://man.freebsd.org/cgi/man.cgi?query=std::numpunct&sektion=3&manpath=FreeBSD+Ports+15.0>

home | help