Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      std::moneypunct<CharT,International>::pos_format, do_pos_format, neg_format, do_neg_format

      From cppreference.com
      <cpp‎ |locale‎ |moneypunct
       
       
       
      Localization library
       
       
      Defined in header<locale>
      public:
      pattern pos_format()const;
      (1)
      public:
      pattern neg_format()const;
      (2)
      protected:
      virtual pattern do_pos_format()const;
      (3)
      protected:
      virtual pattern do_neg_format()const;
      (4)
      1) Public member function, calls the member functiondo_pos_format of the most derived class.
      2) Public member function, calls the member functiondo_neg_format of the most derived class.
      3) Returns the format structure (of typestd::money_base::format) which describes the formatting of positive monetary values.
      4) Returns the format structure (of typestd::money_base::format) which describes the formatting of negative monetary values.

      The standard specializations ofstd::moneypunct return the pattern{symbol, sign, none, value}.

      Contents

      [edit]Return value

      The object of typestd::money_base::format describing the formatting used by this locale.

      [edit]Notes

      Whilestd::money_put usespos_format for formatting positive values and neg_format for formatting negative values,std::money_get usesneg_format for parsing all monetary values: it assumes thatneg_format is compatible withpos_format.

      [edit]Example

      Run this code
      #include <iomanip>#include <iostream>#include <locale> struct my_punct:std::moneypunct_byname<char,false>{    my_punct(constchar* name): moneypunct_byname(name){}    pattern do_pos_format()const{return{value, space, symbol, sign};}    pattern do_neg_format()const{return{value, space, symbol, sign};}}; int main(){std::cout.imbue(std::locale("en_US.utf8"));std::cout<<"american locale: "<<std::showbase<<std::put_money(12345678.0)<<'\n'; std::cout.imbue(std::locale(std::cout.getloc(), new my_punct("en_US.utf8")));std::cout<<"locale with modified moneypunct:\n"<<std::put_money(12345678.0)<<'\n'<<std::put_money(-12345678.0)<<'\n';}

      Output:

      american locale: $123,456.78locale with modified moneypunct:123,456.78 $123,456.78 $-

      [edit]See also

      provides the string to use as the currency identifier
      (virtual protected member function)[edit]
      provides the string to indicate a positive or negative value
      (virtual protected member function)[edit]
      [virtual]
      parses a monetary value from an input stream
      (virtual protected member function ofstd::money_get<CharT,InputIt>)[edit]
      [virtual]
      formats a monetary value and writes to output stream
      (virtual protected member function ofstd::money_put<CharT,OutputIt>)[edit]
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/locale/moneypunct/pos_format&oldid=160160"

      [8]ページ先頭

      ©2009-2026 Movatter.jp