c++小问题,分析(格式化输入输出)

[复制链接]
查看11 | 回复2 | 2009-6-29 21:28:06 | 显示全部楼层 |阅读模式
#include
using namespace std;
int main()
{
double a,b,c,d;
a=23.5790000;
b=12345.8;
c=40.24567894;
d=1000;
/////////////////////////////////////////////////////
cout.setf(ios::scientific);
cout.setf(ios::showpoint);
cout.precision(8);
cout<<a<<endl<<b<<endl<<c<<endl<<d<<endl;
//////////////////////////////////////////////////////
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(8);

cout<<a<<endl<<b<<endl<<c<<endl<<d<<endl;
/////////////////////////////////////////////////////

return 0;
}
结果:
2.35790000e+001
1.23458000e+004
4.02456789e+001
1.00000000e+003
0x1.79439581p+4
0x1.81ce6666p+13
0x1.41f72685p+5
0x1.f4000000p+9
后四行令人费解,什么原因?

回复

使用道具 举报

千问 | 2009-6-29 21:28:06 | 显示全部楼层
这个是有点奇怪,因为ios::fixed 跟 ios::scientific并不是互斥的关系, 你设置后者并没有取消前者,结果就是这样了加上一句 cout.unsetf(ios::scientific)就可以了...
回复

使用道具 举报

千问 | 2009-6-29 21:28:06 | 显示全部楼层
这是我的运行结果,不知道你的是怎么回事。...
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行