#include
<iomanip>
template <class moneyT> T7 get_money(moneyT& mon, bool intl = false) template <class moneyT> T8 put_money(const moneyT& mon, bool intl = false)
Lesen bzw. schreiben Geldbeträge von einem/in einen Zeichenstrom abhängig von der Ländereinstellung.
mon | Geldbetrag als long double oder std::string |
intl | true , wenn internationales Format |
Rückgabewert: Ein- bzw. Ausgabestrom (vom Standard nicht näher definiert).
#include <iostream> #include <iomanip> #include <locale> #include <sstream> 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); if (in) { std::cout << std::quoted(in.str()) << " gelesen als: " << v1 << ", " << v2 << ", " << v3 << '\n'; } else { std::cout << "Nicht gelesen"; } }
Quelle: https://en.cppreference.com/w/cpp/io/manip/get_money