我需要使用C++中的cout打印:
Header
1
2
3
4
5
10
11
12
替换为
Header
1
2
3
4
5
10
11
12
我该如何使用cout来格式化输出?
我需要使用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';
}
setprecision
(控制小数点后的位数)。 - Ben Voigt