How do I correctly organize output into columns?

Posted by wrongusername on Stack Overflow See other posts from Stack Overflow or by wrongusername
Published on 2010-03-12T21:26:22Z Indexed on 2010/03/12 21:37 UTC
Read the original article Hit count: 589

Filed under:
|
|
|

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.

For example, I would like to have something like:

Name    Last Name            Middle initial
Bob     Jones                M
Joe     ReallyLongLastName   T

Instead, by including only "\t"'s in my cout statement I can only manage to get

Name    Last Name            Middle initial
Bob     Jones                M
Joe     ReallyLongLastName                T

or

Name    Last Name            Middle initial
Bob     Jones    M
Joe     ReallyLongLastName   T

What else would I need to do?

© Stack Overflow or respective owner

Related posts about c++

Related posts about cout