fork download
  1. #include <sstream>
  2. #include <string>
  3. #include <ios>
  4. #include <locale>
  5. #include <iostream>
  6. #include <iterator>
  7.  
  8. int main( ) {
  9. std::locale loc("");
  10. std::ios_base::iostate st = std::ios_base::iostate();
  11.  
  12. std::cout.imbue(loc);
  13.  
  14. // force it to show the currency symbol.
  15. std::cout.flags(std::cout.flags()|std::ios_base::showbase);
  16.  
  17. // Get access to the facet:
  18. std::money_put<char> const &mp = std::use_facet<std::money_put<char> >(loc);
  19.  
  20. // Write a value. Treated as integer count of pennies.
  21. mp.put(std::cout.rdbuf(), false, std::cout, st, 12345678);
  22.  
  23. return 0;
  24. };
  25.  
Success #stdin #stdout 0.02s 4892KB
stdin
Standard input is empty
stdout
$123,456.78