How do I correctly organize output into columns?

前端 未结 5 1007
被撕碎了的回忆
被撕碎了的回忆 2020-12-08 04:58

The first thing that comes to my mind is to do a bunch of \\t\'s, but that would cause words to be misaligned if any word is longer than any other word by a few characters.<

5条回答
  •  萌比男神i
    2020-12-08 05:38

    Use std::setw from

    e.g.

    using std::cout;
    using std::setw;
    
    cout << setw(10) << "This" <<
            setw(10) << "is" <<
            setw(10) << "a" <<
            setw(10) << "test" << '\n';
    

    Output:

          This        is         a      test
    

提交回复
热议问题