std::get_money
![]() |
Questa pagina è stata tradotta in modo automatico dalla versione in ineglese della wiki usando Google Translate.
La traduzione potrebbe contenere errori e termini strani. Muovi il puntatore sopra al testo per vedere la versione originale. Puoi aiutarci a correggere gli gli errori. Per ulteriori istruzioni clicca qui. |
Elemento definito nell'header <iomanip>
|
||
template< class MoneyT > /*unspecified*/ get_money( MoneyT& mon, bool intl = false ); |
(dal C++11) | |
When used in an expression in >> get_money(mon, intl), parses the character input as a monetary value, as specified by the std::money_get facet of the locale currently imbued in in
, and stores the value in mon
.
This function behaves as a formatted input function.
Indice |
[modifica] Parametri
mon | - | variable where monetary value will be written. Can be either long double or basic_string |
intl | - | expects to find required international currency strings if true, expects optional currency symbols otherwise |
[modifica] Valore di ritorno
in
è il nome di un flusso di uscita di tipo std::basic_istream<CharT, Traits>, allora l'espressione in >> get_money(mon, intl) comporta come se il codice è stato eseguito il seguente:in
is the name of an output stream of type std::basic_istream<CharT, Traits>, then the expression in >> get_money(mon, intl) behaves as if the following code was executed:You can help to correct and verify the translation. Click here for instructions.
typedef std::istreambuf_iterator<CharT, Traits> Iter;
typedef std::money_get<CharT, Iter> MoneyGet;
std::ios_base::iostate err = std::ios_base::goodbit;
const MoneyGet &mg = std::use_facet<MoneyGet>(in.getloc());
mg.get(Iter(in.rdbuf()), Iter(), intl, in, err, mon);
if (std::ios_base::goodbit != err)
out.setstate(err);
[modifica] Esempio
#include <iostream> #include <sstream> #include <locale> #include <iomanip> int main() { std::istringstream in("$1,234.56 2.22 USD 3.33"); long double 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); std::cout << '"' << in.str() << "\" parsed as: " << v1 << ", " << v2 << ", " << v3 << '\n'; }
Output:
"$1,234.56 2.22 USD 3.33" parsed as: 123456, 222, 333
[modifica] Vedi anche
analizza e costruisce un valore monetario da una sequenza di caratteri di input Original: parses and constructs a monetary value from an input character sequence The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (classe template) | |
(C++11) |
i formati e le uscite di un valore monetario Original: formats and outputs a monetary value The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (funzione di modello) |