cout 格式化输出
来源:互联网 发布:python str什么意思 编辑:程序博客网 时间:2024/05/16 10:33
- 摘自:http://topic.csdn.net/u/20091118/18/eb3d7740-877d-4619-86c5-855d9dba3d95.html
- C/C++ code
- /*关于浮点数的格式*/ #include <iostream> int main() { float 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
- return 0
- } 操纵算子: /*关于浮点数的格式*/ #include <iomanip>
- using namespce std;
- int main() { float f=2.0/3.0,f1=0.000000001,f2=-9.9; 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 return 0;
- }
- cout 格式化输出
- cout格式化输出示例
- cout格式化输出
- cout格式化输出 详解
- cout 格式化输出
- cout 格式化输出
- cout 格式化输出
- cout的格式化输出
- cout 格式化输出详解
- cout 格式化输出详解
- cout的格式化输出
- cout 格式化输出
- cout格式化输出
- cout格式化输出
- cout 格式化输出
- cout 格式化输出
- C++ cout格式化输出
- cout格式化输出
- 编译boost库 boost_1_34
- Java编程体验:线程的7种状态及相互转换(图)
- QT 安装全过程
- Activity的跳转与传值
- 交通灯管理系统
- cout 格式化输出
- 【转】ftp被动模式工作流程
- proxool使用配置
- QwtSplineCurveFitter
- 操作系统 实验四 文件系统管理
- A*算法
- 基于Qt嵌入式媒体播放器系统设计
- 给编好的程序指定参数 方法
- cts 深入分析