c++ i/o控制符

C++常用的I/O流控制符2009-05-12 15:31 控制符 含义 dec 10进制输出数据 hex 16进制输出数据 oct 8进制输出数据 setw(n) 设置每个数占用宽度 setprecision(n) 设置小数位数(含小数点) setioflags(ios::uppercase) 16进制大写输出数据 setioflags(ios::lowercase) 16进制小写输出数据 setioflags(ios::left) 左对齐 setioflags(ios::right) 右对齐 setioflags(ios::showpos) 设置正、负号的显示 setfill(c) 设置填充字符为c endl 换行符 I/O流控制符。 参考源代码: /* 例2-3-1,2-3-1.cpp */ #include #include #include using namespace std ; void main() { double amount = 22.0/7 ; int number = 1001 ; cout << amount << endl ; cout << setprecision(0) << amount << endl / << setprecision(1) << amount << endl / << setprecision(2) << amount << endl / << setprecision(3) << amount << endl / << setprecision(4) << amount << endl ; cout << setiosflags(ios :: fixed); cout << setprecision(8) << amount << endl ; cout << "Decimals:" << dec << number << endl / << "Hexadecimal:" << hex << number << endl / << "Octal:" << oct << number << endl ; cout << setiosflags(ios :: scientific) << amount << endl ; cout << setprecision(6); system("pause"); } 运行结果: 3.14286 3.14286 3 3.1 3.14 3.143 3.14285714 Decimals:1001 Hexadecimal:3e9 Octal:1751 3.1428571
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值