setw question

This is a discussion on setw question within the C++ Programming forums, part of the General Programming Boards category; how can I set a text on the right hand of "setw" to be left justified ??? below the code ...

  1. #1
    Registered User
    Join Date
    Aug 2001
    Posts
    47

    setw question

    how can I set a text on the right hand of "setw" to be left justified ???
    below the code I'm using

    CODE:
    ==============================================
    cout<<setw(20)<<A_String<<endl;

    ==============================================

    what I would like is to have the "A_String" variable to be outputed left justified instead of right justified.....
    I,ve alredy had a look on MSN but still didn't got it.... can someone please post a short example here or just point me the right direction, so that I can look for it.
    Thanks....
    I'm a person with a simple taste...
    I only like the best.

  2. #2
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,793
    Code:
    cout << setw(20) <<  left << A_String << endl;
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

  3. #3
    Registered User
    Join Date
    Aug 2001
    Posts
    47
    I've tryed it alredy but it gives me undeclared identifier..... am I forgetting some header ???
    I'm a person with a simple taste...
    I only like the best.

  4. #4
    Registered User
    Join Date
    Aug 2001
    Posts
    47
    OK... I belive I found out how to put it to work... I just added "using namespace std:" to my code and now the compiler is not complaning about this line of code, nevertheless is now complaning about a "ifstream" and a ofstream" that I have and were working fine before.... please.... help.....
    I'm a person with a simple taste...
    I only like the best.

  5. #5
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    we'll need the code that has the ifstream and ofstream problems to be able to help you.

  6. #6
    Registered User
    Join Date
    Aug 2001
    Posts
    47
    CODE:
    =================================================
    ifstream source("Header.txt");
    source.getline(var1, 30);

    UpdateData(true);

    =================================================

    and the error is " 'ifstream' : anbiguos symbol "
    I'm a person with a simple taste...
    I only like the best.

  7. #7
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    did you remember to #include <fstream> ?

  8. #8
    Registered User
    Join Date
    Aug 2001
    Posts
    47
    ok guys... I finally got it.

    I end up removing the using namespace std and adjusting the previous code to look like this

    CODE:
    ================================================== ==============

    setw(20)<<setiosflags(ios::left)<<A_variable<<endl ;

    ================================================== ==============

    and finally it's working... but the guy that made MSN is responsible for a bunch of my gray hair..... I wonder if they made it so confused and without proper examples to drive us crazy or to stimulate our inventive capabilities :-)
    Thanks for your suport guys...
    I'm a person with a simple taste...
    I only like the best.

  9. #9
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,793
    Might you have possibly been mixing headers, i.e. those with/without the ".h" extensions? Also, left may require you to have included <iomanip>
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

  10. #10
    Registered User
    Join Date
    Aug 2001
    Posts
    47
    YEAP..... I belive that was my problem, I started programming again for fun a year or so ago and I still mix up the headers like hell and ten years ago, when I had to study C++ in college I was using borland C++ wich I remeber having a very good help resources regarding this issue..... now, I never know if I should put "iostream.h" or <iostream.h> or <iostream> ..... I guess pratctice make perfection, I just need to practice more often.

    onca again thanks for the support.
    I'm a person with a simple taste...
    I only like the best.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Debugging question
    By o_0 in forum C Programming
    Replies: 9
    Last Post: 10-10-2004, 05:51 PM
  2. Question about pointers #2
    By maxhavoc in forum C++ Programming
    Replies: 28
    Last Post: 06-21-2004, 12:52 PM
  3. Question...
    By TechWins in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 07-28-2003, 09:47 PM
  4. Question about linked lists.
    By cheeisme123 in forum C++ Programming
    Replies: 6
    Last Post: 02-25-2003, 12:36 PM
  5. Question, question!
    By oskilian in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 12-24-2001, 12:47 AM

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