How do I correctly organize output into columns?

前端 未结 5 992
被撕碎了的回忆
被撕碎了的回忆 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条回答
  •  有刺的猬
    2020-12-08 05:14

    For situations like this typically two passes are required: one to discover the max width of each column and another to do the printing. For standard iostreams you can use the width() routine to have the iostream handle the padding for you automatically.

提交回复
热议问题