Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      std::get_money

      From cppreference.com
      <cpp‎ |io‎ |manip
       
       
       
      Input/output manipulators
      Floating-point formatting
      Integer formatting
      Boolean formatting
      Field width and fill control
      Other formatting
      Whitespace processing
      Output flushing
      Status flags manipulation
      Time and money I/O
      get_money
      (C++11)
      (C++11)
      (C++11)
      (C++11)
      Quoted manipulator
      (C++14)
       
      Defined in header<iomanip>
      template<class MoneyT>
      /*unspecified*/ get_money( MoneyT& mon,bool intl=false);
      (since C++11)

      When used in an expressionin>> get_money(mon, intl), parses the character input as a monetary value, as specified by thestd::money_get facet of the locale currently imbued inin, and stores the value inmon.

      The extraction operation inin>> get_money(mon, intl) behaves as aFormattedInputFunction.

      Contents

      [edit]Parameters

      mon - variable where monetary value will be written. Can be eitherlongdouble orstd::basic_string
      intl - expects to find required international currency strings iftrue, expects optional currency symbols otherwise

      [edit]Return value

      An object of unspecified type such that

      • ifin is an object of typestd::basic_istream<CharT, Traits>, the expressionin>> get_money(mon, intl)
        • has typestd::basic_istream<CharT, Traits>&
        • has valuein
        • behaves as if it calledf(in, mon, intl)

      where the functionf is defined as:

      template<class CharT,class Traits,class MoneyT>void f(std::basic_ios<CharT, Traits>& str, MoneyT& mon,bool intl){using Iter=std::istreambuf_iterator<CharT, Traits>;using MoneyGet=std::money_get<CharT, Iter>; std::ios_base::iostate err=std::ios_base::goodbit;const MoneyGet& mg=std::use_facet<MoneyGet>(str.getloc());     mg.get(Iter(str.rdbuf()), Iter(), intl, str, err, mon); if(err!=std::ios_base::goodbit)        str.setstate(err);}

      [edit]Example

      Run this code
      #include <iomanip>#include <iostream>#include <locale>#include <sstream> int main(){std::istringstream in("$1,234.56 2.22 USD  3.33");longdouble v1, v2;std::string v3;     in.imbue(std::locale("en_US.UTF-8"));    in>> std::get_money(v1)>> std::get_money(v2)>> std::get_money(v3,true); if(in)std::cout<<std::quoted(in.str())<<" parsed as: "<< v1<<", "<< v2<<", "<< v3<<'\n';elsestd::cout<<"Parse failed";}

      Output:

      "$1,234.56 2.22 USD  3.33" parsed as: 123456, 222, 333

      [edit]See also

      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/io/manip/get_money&oldid=159175"

      [8]ページ先頭

      ©2009-2025 Movatter.jp