I have a small problem

when I try to output a set of data, the first set seems to be spaced one more time to the right. this is what parts of it look like:

void reportTitle()
{
ifstream infile;
string name;
double rate;
double hrsWorked;
double taxRate;
double grossAmt;
double netAmt;

infile.open("F:\\payroll.txt");

....

while(!infile.eof())
{
getline(infiile, name, '#');
infile>>rate>>hrsWorked>>taxRate;
grossAmt = rate * hrsWorked;
netAmt = grossAmt - (grossAmt * (taxRate / 100));

cout<<left<<setw(25)<<name<<right<<setw(10)<<rate<<setw(10)<<hrsWorked<<setw(10)<<taxRate<<setw(10)<<netAmt<<endl;
}
cout<<endl;
}

it prints the data like this:

John Smith 22222 xxxxx yyyyy
Erica Jones 22222 xxxxx yyyyy
Jane Doe 22222 xxxxx yyyyy

why does it do that?
[1027 byte] By [ghost_writer] at [2007-11-20 11:30:28]
# 1 Re: I have a small problem
1) Use code tags when posting code.

2) We can't see the format exactly, since the post doesn't show the problem. Maybe using code tags and choosing a fixed-pitch font would solve this problem. Example:

John Smith 22222 xxxxx yyyyy
Erica Jones 22222 xxxxx yyyyy
Jane Doe 22222 xxxxx yyyyy

3) There was no need to introduce the formula. If the problem is printing, just a cout is all you need, maybe just create a simple function that tests some values to output.

#include <iostream>
#include <iomanip>
#include <string>

using namespace std;

void testOutput(const std::string& name, double rate, double hrsWorked,
double taxRate, double grossAmt, double netAmt)
{
cout << left << setw(25) << name << right << setw(10) << rate <<
setw(10) << hrsWorked <<setw(10) << taxRate << setw(10) << netAmt
<< endl;
}

int main()
{
testOutput("John Smith", 20.0, 40.0, 0.30, 800.0, 560.0);
testOutput("Joe Sid", 20.0, 40.0, 0.30, 800.0, 560.0);
}

Something like that. Then you can try various things until it comes out correct. When I try it, the data comes out spaced correctly:

John Smith 20 40 0.3 560
Joe Sid 20 40 0.3 560
Regards,

Paul McKenzie
Paul McKenzie at 2007-11-10 22:25:21 >
# 2 Re: I have a small problem
What version of VC++ are you using ? If I remember
correctly, older versions did not handle setw() with
std::string variables correctly. Use the .c_str() member
function when outputing.

cout<<left<<setw(25)<<name.c_str()
Philip Nicoletti at 2007-11-10 22:26:15 >