fork(1) download
  1. #include <iostream>
  2. #include <sstream>
  3. #include <locale>
  4. #include <climits>
  5.  
  6. struct my_nump : std::numpunct<char> {
  7. std::string do_grouping() const { return "\3"; }
  8. };
  9.  
  10. std::string bigNumberWithCommas(unsigned long long n) {
  11. std::ostringstream s;
  12. if(n > 9999)
  13. s.imbue(std::locale(s.getloc(), new my_nump));
  14. s << n;
  15. return s.str();
  16. }
  17.  
  18. int main()
  19. {
  20. std::cout << bigNumberWithCommas(LLONG_MAX) << '\n'
  21. << bigNumberWithCommas(1234) << '\n';
  22. }
  23.  
Success #stdin #stdout 0s 3480KB
stdin
Standard input is empty
stdout
9,223,372,036,854,775,807
1234