-
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.
-
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;
}