1.fixed
fixed,它表示浮点输出应该以固定点或小数点表示法显示。当然,fixed 操作符可能最重要的还是当它与 setprecision 操作符一起使用时,setprecision 即可以以一种新的方式显示。它将指定浮点数字的小数点后要显示的位数,而不是要显示的总有效数位数。而这通常正是我们想要的。不过,别忘记了包含头文件#include <iomanip> 。
例子ACwing-数的三次方根
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
double n;
scanf("%lf",&n);
double l = -1e4, r = 1e4;
double x;
while(r - l > 1e-8)
{
x = (l + r)/2;
if(x*x*x >= n)r = x;
else l = x;
}
cout <<fixed<< setprecision(6)<< x;
return 0;
}