谈谈C++中如何设置输出格式
来源:互联网 发布:十万元投资知乎 编辑:程序博客网 时间:2024/06/18 14:13
在C++中,要设置浮点数的输出格式,常常用到的函数为cout.setprecision(int),里面的参数为输出浮点数的位数。还是看程序就可以一目了然了。(例程摘自MSDN 2003)
// ios_base_precision.cpp
// compile with:
#include <iostream>
int main( )
{
using namespace std;
float i = 31.31234F;
cout.precision( 3 );
cout << i << endl;
// display three significant digits
cout << fixed << i << endl;
// display three digits after decimal point
}
--------------------------------------------------------
Output
31.3
31.312
从上面程序可以知道,要输出浮点数后几位小数,除了使用cout.setprecision之外,还要在输出是使用fixed.
// ios_base_precision.cpp
// compile with:
#include <iostream>
int main( )
{
using namespace std;
float i = 31.31234F;
cout.precision( 3 );
cout << i << endl;
// display three significant digits
cout << fixed << i << endl;
// display three digits after decimal point
}
--------------------------------------------------------
Output
31.3
31.312
从上面程序可以知道,要输出浮点数后几位小数,除了使用cout.setprecision之外,还要在输出是使用fixed.
- 谈谈C++中如何设置输出格式
- 谈谈C++中如何设置输出格式
- C语言中输出格式
- 如何设置cout的输出格式(转)
- 如何设置cout的输出格式(转)
- 关于SIM28ML中NMEA格式输出设置
- SAP 中如何输出 ALV 格式报表?
- C++中如何控制输出的格式
- C语言中printf()输出格式
- 关于C语言中输出格式
- C语言中控制输出格式
- Smartform输出格式设置
- Endnote输出格式设置
- smartform输出格式设置
- smartform输出格式设置
- c++输出格式设置
- printf 输出格式设置
- Eclipse中如何设置编码格式
- 我 的 精 力
- 女人最美的20瞬间
- C++ Builder 访问 USB 口的方法
- 哪些PHP的framework在国外比较流行(http://blog.csdn.net/Haohappy2004)
- 谈谈C++中如何设置输出格式
- 谈谈C++中如何设置输出格式
- wininet 调用步骤
- 线程+委托 查询数据库
- 优秀网站源码、编程源码下载网站大集中
- 框架与代码关系
- 开始学习OPNET了
- latch,enqueue和semaphore的区别
- PB9转换到PB10
- Servlet action is not available 总结