在C++中,setw()函数是在
#include <iomanip>
std::setw(int n);
其中,n为要设置的字段宽度。例如,如果要设置输出的整数为10个字符宽度,可以使用setw(10)函数。
示例:
#include <iostream>
#include <iomanip>
int main() {
int num1 = 123;
int num2 = 4567;
std::cout << std::setw(10) << num1 << std::endl;
std::cout << std::setw(10) << num2 << std::endl;
return 0;
}
输出结果:
123
4567
在上面的示例中,使用setw()函数设置输出的字段宽度为10个字符,分别输出了num1和num2,并且在输出时会在字段内对齐。
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
推荐阅读:c++中setw函数的作用是什么