开发者

Align Integer using cout in C++

开发者 https://www.devze.com 2023-03-10 06:46 出处:网络
I need C++ to use cout to print: Header 1 开发者_运维问答2 3 4 5 10 11 12 instead of Header 1 2 3 4 5 10 11 12 How should I format this using cout?use the IO manipulator setw

I need C++ to use cout to print:

Header
     1
   开发者_运维问答  2
     3
     4
     5
    10
    11
    12

instead of

Header
    1
    2
    3
    4
    5
    10
    11
    12

How should I format this using cout?


use the IO manipulator 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';
}
0

精彩评论

暂无评论...
验证码 换一张
取 消