#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
double a = 123.456;
double b = 1.2587465;
double c = 6858.1254;
cout<<setiosflags(ios::left)<<setprecision(8)<<setiosflags(ios::fixed); //设置左对齐 设置小数点后精度为8位 设置精度固定
cout<<setw(15)<<a<<endl; //设置数据精度宽度为15
cout<<setw(15)<<b<<endl; //设置数据精度宽度为15
cout<<setw(15)<<c<<endl<<endl; //设置数据精度宽度为15
cout<<setiosflags(ios::right); //设置数据右对齐
cout<<setw(15)<<a<<endl; //设置数据精度宽度为15
cout<<setw(15)<<b<<endl; //设置数据精度宽度为15
cout<<setw(15)<<c<<endl; //设置数据精度宽度为15
system("pause");
return 0;
}
输出结果如下: