#include #include #include #include using namespace std; class commas: public numpunct { public: explicit commas(size_t r = 0): numpunct(r) {} protected: char do_thousands_sep() const {return ',';} string do_grouping() const {return "\x03";} }; inline void print() { cout << setw(12) << 123456789 << " " << right << setw(15) << 123456789.123 << "\n"; } int main() { cout << fixed //to prevent double from appearing in scientific notation << setprecision(3); print(); const locale loc(locale(), new commas); cout.imbue(loc); print(); return EXIT_SUCCESS; }