#include<bits/stdc++.h>
using namespace std;
int main()
{
double x, y;
x = 0.618;
y = 3.14159;
cout<< x << " " << y << endl;
cout<< setprecision(2) << x << " " << y << endl;
cout << setw(10) << x
<< setw(10) << y << endl;
cout << setfill('#') << setw(10) << x
<< setw(10) << y << endl;
system("pause");
}


此代码示例展示了如何使用C++标准库中的`iostream`和`iomanip`来格式化浮点数的输出。它首先直接输出两个浮点数,然后设置精度为2位小数进行输出,并使用`setw`来调整列宽,最后用`setfill`填充字符'#'以保持列宽不变。这有助于理解C++中如何控制浮点数的显示格式。
2568

被折叠的 条评论
为什么被折叠?



