I was just wondering how to align data like this:

McBride, Susan        $ 1000.00        $ 95.00    5
O'Hara, Catherine        $ 2500.00        $ 299.51    5

To make it look like this:

McBride, Susan        $ 1000.00 $    95.00        5
O'Hara, Catherine    $ 2500.00 $  299.51        5

The second part was done by my professor as an example, just like how i would align the numbers to the right like that and to just make it look neat. I've been trying for ever just to try and make my output look presentable.

Recommended Answers

All 5 Replies

Hmm... both examples look exactly the same, because the whitespace doesn't show correctly in HTML. The only way you can make whitespace show is by using [code]

[/code] tags, so you might want to try that to show us better.

In any case, just try using lots of cout.setw() , cout << left , right , and center to align everything (shouldn't be too hard). Just experiment lots.

It doesn't really matter what the file looks like -- how it appears on the screen is a function of the program that displays it. And different programs might display it differently. Font name and font size both influence greatly how the file will look on your monitor.

I may get grief from C++ afficianados but printf() makes it very easy to align data into columns. And it is C++.

the two example looks the same,i think using printf or sprintf is a good idea

I may get grief from C++ afficianados but printf() makes it very easy to align data into columns. And it is C++.

No grief from me:eek: formatting text using printf() is a lot easier than with cout. I never could remember all thouse wiers functions such as setw().

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.