Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      std::money_put

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

         class CharT,
         class OutputIt=std::ostreambuf_iterator<CharT>

      >class money_put;

      Classstd::money_put encapsulates the rules for formatting monetary values as strings. The standard I/O manipulatorstd::put_money uses thestd::money_put facet of the I/O stream's locale.

      std-money put-inheritance.svg

      If astd::money_put specialization is not guaranteed to be provided by the standard library (see below), the behaviors of itsput() anddo_put() are not guaranteed as specified.

      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::money_put<char> creates narrow string representations of monetary values
      std::money_put<wchar_t> creates wide string representations of monetary values

      In addition, the standard library is also guaranteed to provide every specialization that satisfies the following type requirements:

      [edit]Nested types

      Type Definition
      char_typeCharT
      string_typestd::basic_string<CharT>
      iter_typeOutputIt

      [edit]Data members

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

      [edit]Member functions

      constructs a newmoney_put facet
      (public member function)
      invokesdo_put
      (public member function)

      [edit]Protected member functions

      destructs amoney_put facet
      (protected member function)
      [virtual]
      formats a monetary value and writes to output stream
      (virtual protected member function)[edit]

      [edit]Example

      Run this code
      #include <iomanip>#include <iostream>#include <iterator>#include <locale> int main(){// using the I/O manipulatorstd::cout.imbue(std::locale("en_US.UTF-8"));std::cout<<"American locale: "<<std::showbase<<std::put_money(12345678.9)<<'\n'; // using the facet directlystd::cout.imbue(std::locale("de_DE.UTF-8"));std::cout<<"German locale: ";auto& f=std::use_facet<std::money_put<char>>(std::cout.getloc());    f.put({std::cout},false,std::cout,std::cout.fill(),12345678.9);std::cout<<'\n';}

      Output:

      American locale: $123,456.79German locale: 123.456,79 €

      [edit]Defect reports

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

      DRApplied toBehavior as publishedCorrect behavior
      LWG 427C++98money_put was guaranteed to accept anyCharT that
      meets the requirements for a character on which
      any of the iostream components can be instantiated
      only guarantees to acceptchar,
      wchar_t and other implementation-
      defined character types
      LWG 2392C++98only character typeCharT could be
      guaranteed to be accepted bymoney_put
      can guarantee to accept implementation-
      defined character container types

      [edit]See also

      defines monetary formatting parameters used bystd::money_get andstd::money_put
      (class template)[edit]
      parses and constructs a monetary value from an input character sequence
      (class template)[edit]
      (C++11)
      formats and outputs a monetary value
      (function template)[edit]
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/locale/money_put&oldid=178033"

      [8]ページ先頭

      ©2009-2025 Movatter.jp