while loop with !in_stream.eof

.
Last edited on
from your code I would assume your data file looks like:
Another Name
25 8.75
My Name
10 8.5
Third Name
34 10.5

When I would expect:

Another Name 25 8.75
My Name 10 8.5
Third Name 34 10.5

Which is accurate?

I am suspecting you are not reading in the data correctly in either case.

The other thing if Everything is set up correctly:

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

in_stream.open("payroll.txt");
if (in_stream.fail())
{ //unable to open file
cout << "Unable to open file" << endl;
}
else
{ //file open - now can read from it
       // I don't understand why you read the first record before the main loop.
       // Unless it was a preamble of some form.
       while( !in_stream.eof() ) // loop to read records...
       {
               // assuming the first pattern of the data file which I described.
               getline(in_stream, name); 
               in_stream >> hours;
               in_stream >> hourlyRate;

               // blah blah blah... for your code.
       } // end of while.
}// end of if. 


Again I suspect that the data read in choices are wrong because of other problems I have seen that are similar. If that were true, the getline should be in_stream >> firstName; and in_Stream >> lastName; consequently.
Last edited on
.
Last edited on
.
Last edited on
1
2
3
4
5
6

while(1)
{
    printf( "use code tags for your code" );
}


thusly [code] [/code]
Topic archived. No new replies allowed.