cout.setf(ios_base::fixed,ios_base::floatfield);

#include<iostream>
int main()
{
using namespace std;
float hats,heads;
cout.setf(ios_base::fixed,ios_base::floatfield);
cout<<"Enter a number:";
cin>>hats;
cout<<"Enter another number:";
cin>>heads;
cout<<"hats="<<hats<<"; heads="<<heads<<endl;
return 0;

}
程序输出是:
Enter a number:33.3
Enter another number:55.5
hats=33.299999
heads=55.000000
这是什么意思啊,对于cout.setf(ios_base::fixed,ios_base::floatfield);我不明白啊

cout.setf(ios_base::fixed,ios_base::floatfield)

ios_base::fixed是设置cout为定点输出格式
ios_base::floatfield是设置输出时按浮点格式,小数点后有6位数字
温馨提示:答案为网友推荐,仅供参考
第1个回答  2019-03-16
fixed操作符setiosflags
参数之该参数指定动作带小数点形式表示浮点数并且允许精度范围内尽能把数字移向小数点右侧...
floatfield设置输出时按浮点格式小数点有6位数字
相似回答