Thread: iomanip

  1. #1
    Registered User
    Join Date
    Sep 2002
    Posts
    254

    iomanip

    how do i go about outputting text let alligned 12 spaces from the margin? i have been looking into setf but that is a padded output and i want my output to be 12 spaces from the margin and go on from there no matter how long it is
    Code:
    Income:
    <-12 wide-->Hours worked
    Code:
     cout<<setw(12)<<"Hours Worked"<<endl;
    //doesnt quite work as the string is too long so its pushed back agains the margin
    i know its something quite simple but i cant put my finger on it

  2. #2
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    you could just do.....
    Code:
    cout<<"            "<<whateveryouwanthereblahblah;
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

  3. #3
    Registered User
    Join Date
    Sep 2002
    Posts
    254
    Originally posted by Stoned_Coder
    you could just do.....
    Code:
    cout<<"            "<<whateveryouwanthereblahblah;
    yes but then that would be cheating lol i want to do it the right way plus adding spaces is time consuming and a bad idea if i ever have to change the spaces between

  4. #4
    Registered User
    Join Date
    Sep 2002
    Posts
    272
    Check for a newline character. If one is found output x spaces.
    Joe

  5. #5
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    well use a combination of right and setw() but i tell you its gonna be easier to print 12 spaces lol.
    btw if you are on windows console theres a cheat....
    Code:
    #include<windows.h>
    void gotoxy(const int x,const int y)
    {
    COORD point;
    point.X=x;
    point.Y=y;
    SetConsoleCursorPosition(GetStdhandle(STD_OUTPUT_HANDLE),point);
    }
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

  6. #6
    Registered User
    Join Date
    Sep 2002
    Posts
    254
    are you sure there isnt a function specificly for this?

  7. #7
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    absolutely.

    you can use right and setw(12+numcharsinwhateverurprinting)

    cout<<right<<setw(18)<<"Hello.";
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

  8. #8
    S Sang-drax's Avatar
    Join Date
    May 2002
    Location
    Göteborg, Sweden
    Posts
    2,072
    Code:
    cout << setw(12) << "" << "Hours Worked" << endl;
    or am I missing something?

    (edit) No, it seems to work.
    Last edited by Sang-drax; 09-28-2002 at 06:36 AM.
    Last edited by Sang-drax : Tomorrow at 02:21 AM. Reason: Time travelling

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. help with iomanip
    By markucd in forum C++ Programming
    Replies: 1
    Last Post: 04-28-2006, 03:44 AM