How to align numbers in an array

I have 2 arrays that produce this output

joe 10
terry 23
bobby 45

how can I align the numbers so it looks like this

joe      10
terry   23
bobby 45

now I don't know what numeric values will be entered so each time the program runs different numbers could be entered  so it may not just be 2 digits may be 1 digit or 3 digits or digit with decimal point
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

>> how can I align the numbers

One option is to use tabs instead of spaces :

        cout << name << "\t" << value << endl;

Another is to use setw :

        #include <iomanip>

        cout << setw(20) << name << setw(10) << value << endl;
Oops, forgot left in the last example to align left :

        #include <iomanip>

        cout << left << setw(20) << name << setw(10) << value << endl;

The respective reference pages :

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
WestonGroupAuthor Commented:
what about for the input
cout << name <<endl;
cin  >> age ;

name is array
age is array
they are both in a loop for say 12 names

so on the screen you see the input can you format that as well?

WestonGroupAuthor Commented:
nevermind figured it out

>> nevermind figured it out

Nice ;)
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.