Thread: left justify

  1. #1
    Registered User Max's Avatar
    Join Date
    Jul 2002
    Posts
    110

    left justify

    I am trying to print 20 spaces away from the left margin
    But it is not working....anything wrong with my code

    cout.setf(ios::left, ios::adjustfield);
    cout <<"\n\n\n"<<setw(20)<<addr1;

  2. #2
    Registered User
    Join Date
    Jun 2002
    Posts
    82
    Well, assuming you are using std::strings, try:

    Code:
    cout.setf(ios::right, ios::adjustfield);
    cout << "\n\n\n" << setw(20+addr1.length())
         << addr1;
    This will add 20 spaced before the start of whatever you are trying to output.
    Claus Hetzer
    Compiler: Borland 5.5 (on Windows)
    Solaris CC (on Unix)
    Known Languages: C++, MATLAB, Perl, Java

  3. #3
    Registered User Max's Avatar
    Join Date
    Jul 2002
    Posts
    110
    std::strings what is that??

    I am using old c++

  4. #4
    Registered User
    Join Date
    Jun 2002
    Posts
    82
    I mean using string variables instead of char*, like

    Code:
    string thisString;   // this is good
    char[30] thatString; // this is not
    strings have the length() method, which is how I would implement what you are trying to do.
    Claus Hetzer
    Compiler: Borland 5.5 (on Windows)
    Solaris CC (on Unix)
    Known Languages: C++, MATLAB, Perl, Java

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 03:00 PM
  2. pointer to array of objects of struct
    By undisputed007 in forum C++ Programming
    Replies: 12
    Last Post: 03-02-2004, 04:49 AM
  3. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 10:33 AM
  4. setw() - left justify
    By DJPG5 in forum C++ Programming
    Replies: 3
    Last Post: 02-06-2003, 06:46 PM
  5. Please help me
    By teedee46 in forum C++ Programming
    Replies: 9
    Last Post: 05-06-2002, 11:28 PM