C++中设置值的宽度,使用setw

C++中设置值的宽度,使用setw函数。

如:

#include<iomanip>

cout<<setw(4)<<2<<setw(3)<<4<<endl;

输出:2空格空格空格    4空格空格

即2占4位,4占3位。

你可能感兴趣的:(C++中设置值的宽度,使用setw)