How do you set the cout locale to insert commas as thousands separators?

后端 未结 1 2050
谎友^
谎友^ 2020-12-01 19:47

Given the following code:

cout << 1000;

I would like the following output:

1,000

This can be done u

相关标签:
1条回答
  • 2020-12-01 20:21

    The default implementation of do_thousands_sep already returns ','. It looks like you should override do_grouping instead. do_grouping returns an empty string by default, which means no grouping. This means groups of three digits each:

    string do_grouping() const
    {
        return "\03";
    }
    
    0 讨论(0)
提交回复
热议问题