#include<iostream>
#include<iomanip>
using namespace std;
int main(){
int a=6;
cout << setw(3) << setfill('0') << a << endl;//006
cout << a << endl;//6
int b=48;
cout.width(5);
cout.fill('0');
cout << b << endl;//00048
cout << b << endl;//48
int c=51,d=64;
cout << setw(3) << setfill('0') << c << " " <<setw(3) << setfill('0')<< d << endl;//051 064
return 0;
}
cout:控制输出格式之左边补零
最新推荐文章于 2025-03-09 14:25:34 发布
本文介绍在C++中如何使用iomanip库来格式化数字输出,包括设置宽度、填充字符等,适用于需要精确控制数字显示格式的场景。
3702

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



