setw()是设置域宽的函数,默认是前面加空格右对齐。
setfill()是设置填充填充字符。
#include <iostream>
using namespace std;
#include <iomanip>
int main()
{
cout<<setw(8)<<setfill('*')<<123<<endl;
cout<<setw(8)<<456<<endl;
return 0;
}
输出结果是:
*****123
*****456
如果只想填满紧跟后面的,必须重新设置:
#include <iostream>
using namespace std;
#include <iomanip>
int main()
{
cout<<setw(8)<<setfill('*')<<123<<endl;
cout<<setw(8)<<setfill(' ')<<456<<endl;
return 0;
}
注意:重新设置的填充符是空格
这样运行结果是:
*****123
4
相关文章:
-
2022-12-23
-
2022-02-05
-
2022-01-09
-
2022-12-23
-
2022-12-23
-
2021-04-20
-
2022-12-23
-
2022-12-23