How to read complete line in 'for' loop with spaces

1
while(file.good())

is wrong because istream::good() is not intended for use in a while loop condition. Same goes for

while(!file.eof())

.

Typical misuse of these functions is code such as

The typical symptom of this is what people report as "last line was repeated" or "while loop reads extra line". It did not actually read the extra line. It ran off the end of file, the input operation failed, and the value in the variable 'data' was not changed: it was the same value that was obtained on the previous loop iteration. Only the second time around after the end of file the eof()/good() gets a chance to break the loop.

In this case, you have two kinds of input operations: istream::getline, which writes a zero-length C string into the output array when it fails and istream::operator>> which doesn't get a chance to execute after getline()'s failure, so the contents of StartSalary and Age remain unmodified after you run off the end of file.
As you...

0 0
2
...
0 0
3
FORTRAN I/O

FORTRAN: Input/Output (I/O)

SIMPLE I/O: LIST-DIRECTED

The simplest form of the I/O statement is the list-directed form which is represented by: READ(*,*) item1, item2, item3... WRITE(*,*) item1, item2, item3... where ITEMx = a variable, a constant or math expression Example: WRITE(*,*) 'ALPHA=', ALPHA The first asterisk (*) means the input comes from the keyboard in a READ statement and goes to the screen in a WRITE statement. The second asterisk (*) means the computer decides how the I/O elements should look based on the TYPE of data in the input/output list. This is sometimes called "FREE-FORMAT".

NOTES ON LIST-DIRECTED I/O

SPACES may be inserted between components of the statement to add clarity.

The READ statement causes the program to PAUSE and allow you to enter values. The program will not continue until all values have been entered.

Separate values with SPACES when typing data...

0 0