Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1708802
  • 博文数量: 171
  • 博客积分: 11553
  • 博客等级: 上将
  • 技术积分: 3986
  • 用 户 组: 普通用户
  • 注册时间: 2006-05-25 20:28
文章分类

全部博文(171)

文章存档

2012年(2)

2011年(70)

2010年(9)

2009年(14)

2008年(76)

分类: C/C++

2008-03-16 22:05:46

void format_flags()
{

    //使用16进制进行显示数据

    ios::fmtflags old_fmt = cout.setf(ios::hex,ios::basefield);
    //显示数字进制符号0x10,16,020

    cout.setf(ios::showbase);
    
    //显示进制符号的大写形式0X10

    cout.setf(ios::uppercase);
    cout << 16 << endl;
    //不显示进制符号的大写形式0X10

    cout.unsetf(ios::uppercase);
    cout << 16 << endl;
    
    //显示浮点

    cout.setf(ios::showpoint);
    cout << 5.000000 << endl;
    //不显示浮点

    cout.unsetf(ios::showpoint);
    cout << 5.000000 << endl;
    
    ios::fmtflags uppercase = cout.setf(ios::showpos | ios::uppercase);
    cout.unsetf(ios::hex);
    cout << 0 << endl
         <<(2-10) << endl
         << 10 <<endl;

    //设置对齐方式

    cout.setf(ios::right,ios::adjustfield);
    //设置显示宽度

    cout.width(10);
    //设置填充字符,默认为空格

    cout.fill('_');
    cout <<"abc" << endl;

    //设置数字显示格式

    cout.flags(old_fmt);
    //设置显示宽度

    cout.width(10);
    //设置填充字符

    cout.fill('0');
    //设置对齐方式

    cout.setf(ios::internal,ios::adjustfield);
    cout<< -1 << endl;

    //浮点数的格式化输出

    cout.flags(old_fmt);
    cout.setf(ios::showpoint);
    //设置小数位数为10

    cout.precision(10);
    cout << 5.0003333333333 <<endl;

}

阅读(1688) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~