5 Replies - 287 Views - Last Post: 28 January 2013 - 12:34 PM Rate Topic: -----

#1 Nela12  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 35
  • Joined: 16-October 12

How to nicely format contents of array

Posted 26 January 2013 - 04:21 PM

I'm familiar with formatting with iomanip, but my output is horrendous.
Because the data (like city, name , etc ) are all different word lengths, it does not output nicely.
Any tips to make this look nice? In that sense, everything should be in its own column.
Thanks in advance!
Is This A Good Question/Topic? 0
  • +

Replies To: How to nicely format contents of array

#2 CTphpnwb  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 2985
  • Posts: 10,322
  • Joined: 08-August 08

Re: How to nicely format contents of array

Posted 26 January 2013 - 04:23 PM

http://www.cplusplus.../cstdio/printf/
Was This Post Helpful? 0
  • +
  • -

#3 jimblumberg  Icon User is online

  • member icon


Reputation: 4070
  • View blog
  • Posts: 12,557
  • Joined: 25-December 09

Re: How to nicely format contents of array

Posted 26 January 2013 - 04:48 PM

If you are familiar with the functions in the iomanip header you should be able to format the output into columns using these functions. You may want to read up on the setw() function.

Jim
Was This Post Helpful? 0
  • +
  • -

#4 Nela12  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 35
  • Joined: 16-October 12

Re: How to nicely format contents of array

Posted 27 January 2013 - 09:41 PM

I did. Part of the problem is that only 2 or 3 lines dont line up with the column. It's iterates through a for loop, so I am just having trouble thinking of a way to make it all line up nicely. I have setw's '\t's and so on, but those three lines just dont want to adjust.
Was This Post Helpful? 0
  • +
  • -

#5 #define  Icon User is offline

  • Duke of Err
  • member icon

Reputation: 1344
  • View blog
  • Posts: 4,613
  • Joined: 19-February 09

Re: How to nicely format contents of array

Posted 28 January 2013 - 12:03 AM

I wouldn't use tabs. Just find out how much space each column needs.

cout << setw(20) << column_a 
     << setw(15) << column_b 
     << setw(20) << column_c 
     << setw(10) << column_d 
     << endl;




With titles you might need two lines.

Amount   Date   Date
         Due    Received
------------------------

Was This Post Helpful? 0
  • +
  • -

#6 Nela12  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 35
  • Joined: 16-October 12

Re: How to nicely format contents of array

Posted 28 January 2013 - 12:34 PM

I was initially going to do it like that but the for loop saved time because alot of data is being read in from a file. Thank you though! :bigsmile:/>

This post has been edited by Nela12: 28 January 2013 - 12:35 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1