[c++]setw()用法总结

setw()是用来控制后面的输出长度的。

使用需调用:

include<iomanip>

eg:

cout<<setw(5)<<"s"<<endl;

结果为:    s;//四个空格加一个s共占5个字符

 

setw()默认填充为" "(空格),可以通过setfill()命令更改填充字符。

 

eg:

cout<<setfill("*")<<setw(5)<<"s"<<endl;

结果为:****s;

 

参考:http://www.cplusplus.com/reference/iomanip/setw/

https://zhidao.baidu.com/question/358913227.html

转载于:https://www.cnblogs.com/Faiz-room/p/6171418.html