Thread: alignment of output

  1. #1
    Shake Zula- The Mic Rula!
    Join Date
    Sep 2004
    Posts
    69

    alignment of output

    i am just curious if there is a way to set a "right justification" of data instead of using "setw" as i have in this example....
    Code:
    cout<<"Total number of probes in Unordered Array: "<<setw (25)<<total_probes<<endl;
    cout<<"Total number of probes in Ordered Array:  "<<setw (26)<<total_probes2<<endl;
    cout<<"Total number of probes in {binary search} of Ordered Array: "<<setw (8)<<total_probes3<<endl;
    cout<<"Total number of probes for all arrays were:"<<setw (25)<<total_probes + total_probes2 + total_probes3<<endl;

  2. #2
    Registered User
    Join Date
    Sep 2001
    Posts
    4,912
    I don't know of any standard way. It wouldn't be too hard to write an output function that does it yourself. The standard console window is usually 80 characters in width. Just count the characters, subtract from 80, and add the appropriate spaces.

  3. #3
    Been here, done that.
    Join Date
    May 2003
    Posts
    1,164
    Quote Originally Posted by bcianfrocca
    i am just curious if there is a way to set a "right justification" of data instead of using "setw" as i have in this example....
    Code:
    cout<<"Total number of probes in Unordered Array: "<<setw (25)<<total_probes<<endl;
    cout<<"Total number of probes in Ordered Array:  "<<setw (26)<<total_probes2<<endl;
    cout<<"Total number of probes in {binary search} of Ordered Array: "<<setw (8)<<total_probes3<<endl;
    cout<<"Total number of probes for all arrays were:"<<setw (25)<<total_probes + total_probes2 + total_probes3<<endl;
    Personally, I find printf() to be far superior and much more logical to use for formatted I/O. Numbers are automatically right-justified, strings are left.
    Definition: Politics -- Latin, from
    poly meaning many and
    tics meaning blood sucking parasites
    -- Tom Smothers

  4. #4
    Handy Andy andyhunter's Avatar
    Join Date
    Dec 2004
    Posts
    540
    Tis a shame we are on the C++ board here. Thanx for your input though.
    i don't think most standard compilers support programmers with more than 4 red boxes - Misplaced

    It is my sacred duity to stand in the path of the flood of ignorance and blatant stupidity... - quzah

    Such pointless tricks ceased to be interesting or useful when we came down from the trees and started using higher level languages. - Salem

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. code output...
    By roaan in forum C Programming
    Replies: 6
    Last Post: 07-03-2009, 02:22 AM
  2. Help for my output array
    By qwertysingh in forum C Programming
    Replies: 1
    Last Post: 02-17-2009, 03:08 PM
  3. execl()/fork() output
    By tadams in forum C Programming
    Replies: 19
    Last Post: 02-04-2009, 03:29 PM
  4. Formatting output into even columns?
    By Uncle Rico in forum C Programming
    Replies: 2
    Last Post: 08-16-2005, 05:10 PM
  5. Output problems with structures
    By Gkitty in forum C Programming
    Replies: 1
    Last Post: 12-16-2002, 05:27 AM