#include<iostream>
int main()
{
using namespace std;
int n = 13;
cout.width(7); // 填充宽度,只影响下一个显示的项目,之后恢复默认值
cout.fill('*'); // 填充字符(fill character) ,默认对齐方式右对齐,插在值的左侧,一直有效,直到更改
cout << left << n << " "; //控制符left,变为左对齐,一直有效,直到更改
cout.width(7);
cout << right << n << endl; // right,变为右对齐
float b = 12.156;
cout.precision(2); // 设置精度,四舍五入,一直有效,直到更改
cout << b << endl;
cout << fixed << b << endl; // 如果precision函数没有配合fixed使用的话,则精度表示小数整体的位数(不包括小数点)
return 0;
}
未使用头文件iomanip, 设置输出宽度,精度