setw within a loop only works on the first iteration

I am trying to output data that I have read in from a pound sign delimited file. Here is the appropriate section of code as I have written:

string tool;
double temp;

while (!inData.eof())
{
getline (inData,tool,'#');
inData >> temp;
cout << setw (20) << tool << setw(9) << temp;
}

For the first line from the file that the program reads, the setw command works as I expected it to: the string in tool is right justified 20 spaces over, and the temp variable is right justified 9 spaces from there.
For the second, third, and all subsequent reads from the file, the tool variable is left justified with no set width, and the temp variable is right justified 9 spaces.

Is there something I am missing related to the data I'm putting into temp being the end of the line that is causing the setw not to do what I think it should on later passes through the loop? Or is there something else that I am missing?

I've looked through my book some, and haven't found anything. Clearly, I'm a beginner, so I expect this to be a simple thing that I have missed.

Thanks
Last edited on
I don't know if this was the corret fix, but I've added the italics code, and I'm at least now getting the output I wanted to see.

string tool;
double temp;

while (!inData.eof())
{
getline (inData,tool,'#');
inData >> temp;
inData.ignore(1,'/n');
cout << setw (20) << tool << setw(9) << temp << endl;
}

If there is a better way to have done this, I'd be interested in learning.

Thanks
Topic archived. No new replies allowed.