我需要 C++ 来使用 cout 打印:
Header
1
2
3
4
5
10
11
12
代替
Header
1
2
3
4
5
10
11
12
我应该如何使用 cout 对其进行格式化?
最佳答案
使用IO操纵器setw
#include <iostream>
#include <iomanip>
int main()
{
std::cout << "Header\n";
for(int i=1; i<13; ++i)
std::cout << std::setw(6) << i << '\n';
}
关于c++ - 在 C++ 中使用 cout 对齐整数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6222592/