std::put_money(3)
πΈ NAME πΈ
std::put_money β std::put_money. Bestie, the NAME section is literally repeating itself and honestly? Iconic behavior. This is the std::put_money(3) page from the C++ Standard Libary (that spelling is from the header, not me π
).
β¨ Synopsis β¨
Defined in header <iomanip> β yes, that's where it lives, bestie.
Since C++11 (the template was born then, periodt):
template< class MoneyT >
/*unspecified*/ put_money( const MoneyT& mon, bool intl = false );
When used in an expression out << put_money(mon, intl), it converts the monetary value mon to its character representation as specified by the std::money_put facet of the locale currently imbued in out.
The insertion operation in out << put_money(mon, intl) behaves as a FormattedOutputFunction. No cap, that's the whole vibe check.
π Parameters π
monβ a monetary value, eitherlong doubleorstd::basic_string.intlβ use international currency strings iftrue, use currency symbols otherwise.
π Return value π
An object of unspecified type such that:
- if
outis an object of typestd::basic_ostream<CharT, Traits>, the expressionout << put_money(mon, intl)- has type
std::basic_ostream<CharT, Traits>& - has value
out - behaves as a
FormattedOutputFunctionthat callsf(out, mon, intl)
- has type
where the function f is defined as:
template<class CharT, class Traits, class MoneyT>
void f(std::basic_ios<CharT, Traits>& str, const MoneyT& mon, bool intl)
{
using Iter = std::ostreambuf_iterator<CharT, Traits>;
using MoneyPut = std::money_put<CharT, Iter>;
const MoneyPut& mp = std::use_facet<MoneyPut>(str.getloc());
const Iter end = mp.put(Iter(str.rdbuf()), intl, str, str.fill(), mon);
if (end.failed())
str.setstate(std::ios_base::badbit);
}
π§ Example π§
The page literally says // Run this code, so here's the code, bestie:
#include <iomanip>
#include <iostream>
int main()
{
long double mon = 123.45; // or std::string mon = "123.45";
std::cout.imbue(std::locale("en_US.UTF-8"));
std::cout << std::showbase
<< "en_US: " << std::put_money(mon)
<< " or " << std::put_money(mon, true) << '\n';
std::cout.imbue(std::locale("ru_RU.UTF-8"));
std::cout << "ru_RU: " << std::put_money(mon)
<< " or " << std::put_money(mon, true) << '\n';
std::cout.imbue(std::locale("ja_JP.UTF-8"));
std::cout << "ja_JP: " << std::put_money(mon)
<< " or " << std::put_money(mon, true) << '\n';
}
π Possible output π
en_US: $1.23 or USD 1.23
ru_RU: 1.23 ΡΡΠ± or 1.23 RUB
ja_JP: οΏ₯123 or JPY 123
π¦ See also π¦
money_putβ formats a monetary value for output as a character sequence (class template)get_moneyβ parses a monetary value (C++11) (function template)
okay bestie, that's the whole page π«Άπ β source: cppreference.com, version/date: 2024.06.10. now go format some money and slay β¨π
π¦ where this page comes from
- nixpkgs unstable: stdman 2024.07.05
- opensuse-leap 16.0: stdman 2024.07.05-bp160.1.9 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms