Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      std::numpunct

      From cppreference.com
      <cpp‎ |locale
       
       
       
      Localization library
       
       
      Defined in header<locale>
      template<class CharT>
      class numpunct;

      The facetstd::numpunct encapsulates numeric punctuation preferences. Stream I/O operations usestd::numpunct throughstd::num_get andstd::num_put for parsing numeric input and formatting numeric output.

      The numbers that are supported bystd::numpunct have the format described below. Heredigit represents the radix set specified by thefmtflags argument value,thousands-sep anddecimal-point are the results ofthousands_sep() anddecimal_point() functions respectively.

      The format of integer values is as follows:

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

      The number of digits between thethousand-seps (maximum size ofdigits) is specified by the result ofgrouping().

      The format of floating-point values is as follows:

      floatval    ::= [sign] units [decimal-point [digits]] [e [sign] digits] |                [sign]        decimal-point  digits   [e [sign] digits]e           ::= 'e' | 'E'
      std-numpunct-inheritance.svg

      Contents

      [edit]Specializations

      The standard library is guaranteed to provide the following specializations (they arerequired to be implemented by any locale object):

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

      [edit]Nested types

      Type Definition
      char_typeCharT
      string_typestd::basic_string<CharT>

      [edit]Data members

      Member Description
      std::locale::idid[static] the identifier of thefacet

      [edit]Member functions

      constructs a newnumpunct facet
      (public member function)[edit]
      destructs anumpunct facet
      (protected member function)[edit]
      invokesdo_decimal_point
      (public member function)[edit]
      invokesdo_thousands_sep
      (public member function)[edit]
      invokesdo_grouping
      (public member function)[edit]
      invokesdo_truename ordo_falsename
      (public member function)[edit]

      [edit]Protected member functions

      provides the character to use as decimal point
      (virtual protected member function)[edit]
      provides the character to use as thousands separator
      (virtual protected member function)[edit]
      [virtual]
      provides the numbers of digits between each pair of thousands separators
      (virtual protected member function)[edit]
      provides the string to use as the name of the booleantrue andfalse
      (virtual protected member function)[edit]

      [edit]Example

      The following example changes the string representations oftrue andfalse:

      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, falselocale with modified numpunct: vrai, faux

      [edit]Defect reports

      The following behavior-changing defect reports were applied retroactively to previously published C++ standards.

      DRApplied toBehavior as publishedCorrect behavior
      LWG 338C++98thesign token allowed an optional whitespace following+ or-removed the whitespace

      [edit]See also

      creates a numpunct facet for the named locale
      (class template)
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/locale/numpunct&oldid=179744"

      [8]ページ先頭

      ©2009-2025 Movatter.jp