Problems with "\t"

This is a discussion on Problems with "\t" within the C++ Programming forums, part of the General Programming Boards category; Hi all, I have a question. I have a function in my class that I am building that goes like ...

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

    Problems with "\t"

    Hi all,
    I have a question. I have a function in my class that I am building that goes like this:
    Code:
    void Ballot::Display()
      // In essence, this would be the display for one ballot
      // the format should be like the following:
      // 1)       Bush      Punched       Age: 23
    {
      // since this is the display for one ballot card
      // we put the number list in the Tally::Display()
      switch(who)
        {
        case BUSH:      cout << "Bush\t"; break;
        case GORE:      cout << "Gore\t"; break;
        case BUCHANAN:  cout << "Buchanan\t"; break;
        case OTHER:     cout << "Other\t"; break;
        case MULTIPLE:  cout << "Multiple\t"; break;
        }
      switch(mark)
        {
        case PUNCHED:   cout << "Punched\t"; break;
        case HANGING:   cout << "Hanging\t"; break;
        case DIMPLED:   cout << "Dimpled\t"; break;
        case NONE:      cout << "None\t"; break;
        }
      cout << "Age: " << age;
    
    }
    To me, I should expect it to give an output of:
    Code:
    Bush         Punched        Age: 21
    // depending on the user choices of course
    Instead, its giving me:
    Code:
    Bush        Punched Age: 21
    I know that we can use the <iomanip> header file for that but how? Thank you.

  2. #2
    Comment your source code! Lynux-Penguin's Avatar
    Join Date
    Apr 2002
    Posts
    533
    are you talking about setw() ?

    setw() sets up a field around your output. Very useful for making tables or charts.
    make sure you also use setiosflags(ios::left or ios::right)
    ex:
    Code:
    #include <iostream.h>
    #include <iomanip.h>
    
    int main()
    {
    	
    	setiosflags(ios::left);
    	cout<<"Name"<<setw(10)<<"Date"<<endl;
    	return 0;
    }
    if you just want to fix your code...
    I'm not sure exactly but try this:
    Code:
    void Ballot::Display()
      // In essence, this would be the display for one ballot
      // the format should be like the following:
      // 1)       Bush      Punched       Age: 23
    {
      // since this is the display for one ballot card
      // we put the number list in the Tally:isplay()
      switch(who)
        {
        case BUSH:      cout << "Bush\t"; break;
        case GORE:      cout << "Gore\t"; break;
        case BUCHANAN:  cout << "Buchanan\t"; break;
        case OTHER:     cout << "Other\t"; break;
        case MULTIPLE:  cout << "Multiple\t"; break;
        }
      switch(mark)
        {
        case PUNCHED:   cout << "Punched\t"; break;
        case HANGING:   cout << "Hanging\t"; break;
        case DIMPLED:   cout << "Dimpled\t"; break;
        case NONE:      cout << "None\t"; break;
        }
      cout << "\tAge:\t" << age;
    
    }
    Asking the right question is sometimes more important than knowing the answer.
    Please read the FAQ
    C Reference Card (A MUST!)
    Pointers and Memory
    The Essentials
    CString lib

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. No clue how to make a code to solve problems!
    By ctnzn in forum C Programming
    Replies: 8
    Last Post: 10-16-2008, 02:59 AM
  2. C Pointers Problems
    By mhelal in forum C Programming
    Replies: 8
    Last Post: 01-10-2007, 05:35 AM
  3. Rendering problems (DirectX?)
    By OnionKnight in forum Tech Board
    Replies: 0
    Last Post: 08-17-2006, 12:17 PM
  4. contest problems on my site
    By DavidP in forum Contests Board
    Replies: 4
    Last Post: 01-10-2004, 08:19 PM
  5. DJGPP problems
    By stormswift in forum C Programming
    Replies: 2
    Last Post: 02-26-2002, 03:35 PM

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