Thread: setwidth help

  1. #1
    Registered User
    Join Date
    Oct 2008
    Posts
    3

    Exclamation setwidth help

    I am trying to create a graph similar to this

    ---------year ---------population1 ---------population2
    ### ####### #######
    #### ##### #######
    #### ###### #######


    except perfectly aligned no matter what info is entered. This is for a C++ assignment due in an hour, I forgot my book, and I can't remember how to use setwidth. HELP!

    I apparently can't get it to show up how I want it to on the forum - it should be 3 columns all aligned to the right with the year, followed by the 2 populations. the system will be created using a loop statement to recalculate the estimated population based on the year showing pop for every 5 years until it reaches 100 years
    Last edited by feltrockni; 11-10-2008 at 06:16 PM. Reason: STILL not showing up right

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    You should look it up -- google setw, or go to cplusplus.com and search there.

  3. #3
    Registered User
    Join Date
    Oct 2008
    Posts
    3
    thanks, doing that now. But any extra help would still be great.

    edit: got it
    Last edited by feltrockni; 11-10-2008 at 06:22 PM.

  4. #4
    Registered User
    Join Date
    Apr 2006
    Posts
    137
    I believe you use it like this:

    don't forget to include <iomanip>
    cout << "Some text" << setwidth(5) << "Another text" << setwidth(5) << "Last text" << endl;

    It adds some spacing. You may have to experiment with how long it should be.
    ★ Inferno provides Programming Tutorials in a variety of languages. Join our Programming Forums. ★

  5. #5
    Registered User
    Join Date
    Oct 2008
    Posts
    3
    got it working, thanks a lot. Assignment finished on time.

Popular pages Recent additions subscribe to a feed

Tags for this Thread