cout的输出格式初探3
2015-07-09 09:43
841 查看
#include <iostream> #include <iomanip> using namespace std; int main() { double f=2.0/3.0,f1=0.000000001,f2=-9.9; cout<<f<<' '<<f1<<' '<<f2<<endl; //正常输出 cout.setf(ios::showpos); //强制在正数前加+号 //表示出正负号 cout<<f<<' '<<f1<<' '<<f2<<endl; cout.unsetf(ios::showpos); //取消正数前加+号 cout.setf(ios::showpoint); //强制显示小数点后的无效0 cout<<f<<' '<<f1<<' '<<f2<<endl; cout.unsetf(ios::showpoint); //取消显示小数点后的无效0 cout.setf(ios::scientific); //科学记数法 cout<<f<<' '<<f1<<' '<<f2<<endl; cout.unsetf(ios::scientific); //取消科学记数法 cout.setf(ios::fixed); //按点输出显示 cout<<f<<' '<<f1<<' '<<f2<<endl; cout.unsetf(ios::fixed); //取消按点输出显示 cout.precision(18); //精度为18,正常为6 cout<<f<<' '<<f1<<' '<<f2<<endl; cout.precision(6); //精度恢复为6 cout<<f<<' '<<f1<<' '<<f2<<endl; cout<<"----------------------------"<<endl; //使用操作算法,效果相同 cout<<f<<' '<<f1<<' '<<f2<<endl; //正常输出 cout<<setiosflags(ios::showpos); //强制在正数前加+号 cout<<f<<' '<<f1<<' '<<f2<<endl; cout<<resetiosflags(ios::showpos); //取消正数前加+号 cout<<setiosflags(ios::showpoint); //强制显示小数点后的无效0 cout<<f<<' '<<f1<<' '<<f2<<endl; cout<<resetiosflags(ios::showpoint); //取消显示小数点后的无效0 cout<<setiosflags(ios::scientific); //科学记数法 cout<<f<<' '<<f1<<' '<<f2<<endl; cout<<resetiosflags(ios::scientific); //取消科学记数法 cout<<setiosflags(ios::fixed); //按点输出显示 cout<<f<<' '<<f1<<' '<<f2<<endl; cout<<resetiosflags(ios::fixed); //取消按点输出显示 cout<<setprecision(18); //精度为18,正常为6 cout<<f<<' '<<f1<<' '<<f2<<endl; cout<<setprecision(6); //精度恢复为6 cout<<f<<' '<<f1<<' '<<f2<<endl; return 0; }
程序运行结果如下:
相关文章推荐
- js默认行为(也称默认事件)
- jQuery实现鼠标点击弹出渐变层的方法
- nyoj-307 宝物【dp+贪心】
- ANSI转UNICODE之基础篇
- 《Yaf零基础学习总结》系列技术文章整理收藏
- 求一个整数四舍五入后的结果,该整数可以是正数负数
- test
- python实现用户登陆邮件通知的方法
- 欢迎使用CSDN-markdown编辑器
- 提高团队战斗力的几点建议
- mongodb入门
- python 显示unicode字符问题
- BZOJ 1026 Windy数
- select2美化下拉单
- Lua脚本语言基本语法快速入门教程
- CentOS 6 Iptables关于--hitcount数值限制的问题
- linux运维
- 循环体中用“+”拼接字符串-代码典型缺陷分析
- cout的输出格式初探2
- 数字的颠倒