fork download
  1. #include <iostream>
  2. #include <iomanip>
  3. #include <sstream>
  4. #include <locale>
  5.  
  6. using namespace std;
  7.  
  8. class Foo : public std::moneypunct<char> {
  9. protected:
  10. char_type do_decimal_point() const {
  11. cout << "Hit Foo::do_decimal_point";
  12. return ',';
  13. }
  14. char_type do_thousands_sep() const {
  15. cout << "Hit Foo::do_thousands_sep";
  16. return '.';
  17. }
  18. };
  19.  
  20. int main()
  21. {
  22. cout.imbue(locale(locale("C"), new Foo));
  23.  
  24. const moneypunct<char>* temp = &use_facet<std::moneypunct<char>>(cout.getloc());
  25.  
  26. cout << temp->decimal_point() << endl << temp->thousands_sep() << endl;
  27.  
  28. istringstream USCurency("1,234.56 -1,234.56 1.234,56 -1.234,56");
  29. USCurency.imbue(cout.getloc());
  30.  
  31. long double value;
  32.  
  33. USCurency >> get_money(value, true);
  34.  
  35. return 0;
  36. }
Success #stdin #stdout 0s 3276KB
stdin
Standard input is empty
stdout
Hit Foo::do_thousands_sepHit Foo::do_decimal_point,
.