#include<iostream>
#include <iomanip>
using namespace std;
int main() {
// 小数右侧补0
double a = 10.12345;
cout << fixed << a << endl;
cout << fixed << setprecision(2) << a << endl;
cout << fixed << setprecision(7) << a << endl;
cout << endl;
// 整数左侧补0
int b = 123;
cout << setw(4) << b << endl;
cout << setw(4) << setfill('0') << b << endl;
cout << setw(4) << setfill('k') << b << endl;
return 0;
}
结果:
10.123450
10.12
10.1234500
123
0123
k123