This can be done using faces.
struct myseps : numpunct<char> { char do_thousands_sep() const { return ' '; } string do_grouping() const { return "\3"; } }; int main() { std::cout.imbue(std::locale(std::locale(), new myseps)); std::cout << 10000;
Alternatively, you can program your own loop
void printGrouped(ostream &out, int n) { if(n < 0) { out << "-"; return printGrouped(out, -n); } if(n < 1000) { out << n; } else { printGrouped(out, n / 1000); out << " " << setw(3) << setfill('0') << (n % 1000); } } ostream & operator<< (ostream & out, const Currency & c) { printGrouped(out, c.val); out << " " << c.curr; return out; }
Johannes Schaub - litb Apr 15 '10 at 20:00 2010-04-15 20:00
source share