Right justify?!?!

This is a discussion on Right justify?!?! within the C++ Programming forums, part of the General Programming Boards category; Hi Guys!! I want to output a total, that is right justified, but I just can't seem the code to ...

  1. #1
    Registered User
    Join Date
    Jan 2002
    Posts
    10

    Unhappy Right justify?!?!

    Hi Guys!!
    I want to output a total, that is right justified, but I just can't seem the code to work!!!

    This is what I have:
    cout << "Room charge is:" << setw(8) << setiosflags(ios:: right) << setiosflags(ios::showpoint) << setiosflags(ios:: fixed) << setprecision(2) << roomCharge << endl;

    Am I doing' something very wrong!? I have #include <iomanip> up top of my code, so I can't figure it out!!
    Can anyone help?!

    Cheers,
    Claire

  2. #2
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    try either....
    cout << "Room charge is:" << setw(8) << setf(ios:: right) << setf(ios::showpoint) << setf(ios:: fixed) << setprecision(2) << roomCharge << endl;
    or
    cout << "Room charge is:" << setw(8) << right << showpoint << fixed << setprecision(2) << roomCharge << endl;
    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
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,831
    >>>
    cout << "Room charge is:" << setw(8) << setf(ios:: right) << setf(ios::showpoint) << setf(ios:: fixed) << setprecision(2) << roomCharge << endl;
    <<<


    Makes you kind of glad printf() is still available!
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  4. #4
    Fingerstyle Guitarist taylorguitarman's Avatar
    Join Date
    Aug 2001
    Posts
    564
    Testify to that.

  5. #5
    Registered User
    Join Date
    Jan 2002
    Posts
    10

    How do you delcare to use setf...

    Hi...
    I tried using your code you gave to right justify, but when I compile, I get an error msg saying:

    implicit declaration of function `int setf(.

    How do I declare it so that I can use it?!

    Thanks!!
    Claire

  6. #6
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    sorry my bad..... try just using the manipulators.That will work. otherwise try this.

    cout.setf(ios::fixed|ios::showpoint|ios::right);
    cout<<setw(8)<<setprecision(2)<<RoomCharge<<endl;
    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

  7. #7
    Unregistered
    Guest
    try adding the iomanip.h (or equivalent) header file in your list files that are #included.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How do I right justify this?
    By hermancarson in forum C Programming
    Replies: 4
    Last Post: 11-19-2007, 11:27 AM
  2. setw() - left justify
    By DJPG5 in forum C++ Programming
    Replies: 3
    Last Post: 02-06-2003, 06:46 PM
  3. how to right justify toolbar ??
    By Feras in forum Windows Programming
    Replies: 1
    Last Post: 12-06-2002, 04:36 PM
  4. left justify
    By Max in forum C++ Programming
    Replies: 3
    Last Post: 10-21-2002, 07:32 PM
  5. right justify a text file
    By Unregistered in forum C++ Programming
    Replies: 2
    Last Post: 02-11-2002, 01:17 AM

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