a question about output

This is a discussion on a question about output within the C++ Programming forums, part of the General Programming Boards category; How to output something like this in c++? (first part of each line is left aligned, second part is right ...

  1. #1
    Registered User
    Join Date
    Mar 2006
    Posts
    25

    a question about output

    How to output something like this in c++? (first part of each line is left aligned, second part is right aligned)
    ********* **
    ******* ****
    ******* ****
    ********** *
    Last edited by f6ff; 04-03-2006 at 04:43 PM.

  2. #2
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,801
    Quote Originally Posted by f6ff
    a question about output
    Quote Originally Posted by f6ff
    How to input something like this in c++?
    Well, are you asking about input or output?
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

  3. #3
    Registered User
    Join Date
    Jan 2005
    Posts
    7,327
    The console uses fixed width font, so to align something to the right you will probably just have to figure out how many spaces to add between the characters on the right and the ones on the left. That should only take some pretty simple math.

  4. #4
    Registered User
    Join Date
    Mar 2006
    Posts
    25
    Quote Originally Posted by hk_mp5kpdw
    Well, are you asking about input or output?
    It's output

  5. #5
    Registered User
    Join Date
    Mar 2006
    Posts
    25
    I tried this to make ptr->count organizing, but not working
    Code:
    cout <<setw(30-(ptr->data.size()))<< ptr->data <<setw(30)<<ptr->count

  6. #6
    Registered User
    Join Date
    Jan 2005
    Posts
    7,327
    I don't think you need to use setw for this. Why not just calculate the number of spaces required and output them in a loop?

  7. #7
    Registered User
    Join Date
    Mar 2006
    Posts
    25
    Quote Originally Posted by Daved
    I don't think you need to use setw for this. Why not just calculate the number of spaces required and output them in a loop?
    that will work, thanks

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Question: Output of data.txt from the following program
    By outlaw525 in forum C Programming
    Replies: 9
    Last Post: 06-23-2008, 03:33 PM
  2. strange virtual function output
    By George2 in forum C++ Programming
    Replies: 4
    Last Post: 02-08-2008, 07:08 AM
  3. Basic C input output program help
    By trevordunstan in forum C Programming
    Replies: 2
    Last Post: 01-27-2008, 05:41 PM
  4. a question about file output
    By wang8442 in forum C Programming
    Replies: 3
    Last Post: 12-26-2004, 02:18 AM
  5. a newbie question about file output
    By maybe in forum C Programming
    Replies: 8
    Last Post: 10-12-2004, 08:14 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21