fork download
  1. #include <iostream>
  2. #include <locale>
  3. #include <sstream>
  4.  
  5. using namespace std;
  6.  
  7. struct thousand_formater : numpunct<char>
  8. {
  9. // separate with spaces
  10. char do_thousands_sep() const { return '.'; }
  11.  
  12. // groups of 1 digit
  13. string do_grouping() const { return "\03"; }
  14. };
  15.  
  16. int main()
  17. {
  18. cout.imbue(locale(cout.getloc(), new thousand_formater));
  19.  
  20. cout << 110 << endl;
  21. cout << 1500 << endl;
  22. cout << 13200 << endl;
  23. cout << 500000 << endl;
  24. cout << 99999999 << endl;
  25.  
  26. // string
  27. stringstream ss;
  28. ss.imbue(locale(cout.getloc(), new thousand_formater));
  29. ss << 89898989;
  30.  
  31. string resultado = ss.str();
  32.  
  33. cout << resultado << endl;
  34. }
Success #stdin #stdout 0.01s 5348KB
stdin
Standard input is empty
stdout
110
1.500
13.200
500.000
99.999.999
89.898.989