正文

为数字加逗号分割2007-08-30 15:22:00

【评论】 【打印】 【字体: 】 本文链接:http://blog.pfan.cn/aurora/28997.html

分享到:

bruceteen的方法(使用一个如此设置的local):#include <iostream>#include <locale> int main( void ){    using namespace std;     cout << 1389992 << endl; // 1389992     locale chs( "chs" ); // chs在我这里行,不知道你那里怎么样    cout.imbue( chs );    cout << 1389992 << endl; // 1,389,992} 特别推荐 namtso的方法(自己订制local):#include <iostream>#include <string>#include <locale>using namespace std; class thousands_sep_facet:public std::numpunct<char>{public:    explicit thousands_sep_facet( size_t r=0 ) : std::numpunct<char>(r)    {    }protected:    string do_grouping() const    {        return "\003";    }}; int main( void ){    cout << 1389992 << endl; // 1389992     locale loc( locale(), new thousands_sep_facet );    std::cout.imbue( loc );    cout << 1389992 << endl; // 1,389,992     return 0;}

阅读(4846) | 评论(0)


版权声明:编程爱好者网站为此博客服务提供商,如本文牵涉到版权问题,编程爱好者网站不承担相关责任,如有版权问题请直接与本文作者联系解决。谢谢!

评论

暂无评论
您需要登录后才能评论,请 登录 或者 注册