I'll walk you through what's going on.
A
1 2
|
fstream infile;
infile.open(name);
|
You should already know this one.
B
1 2
|
while (!infile.eof())
{
|
As long as we haven't reached the end of the file, follow the inside of this loop
C
1 2
|
infile >> aStudent.number >> aStudent.dob.day >> aStudent.dob.month >> aStudent.dob.year >> aStudent.scores[0] >>
aStudent.scores[1] >> aStudent.scores[2] >> aStudent.scores[3] >> aStudent.scores[4] >> aStudent.scores[5];
|
Since the file is open, we read values into aStudent, then the 5 scores into an array of scores (I'm assuming that your NUM_SCORES variable is = 5)
D
1 2 3
|
cout << "Student Number\t" << "DOB\t\t" << "Student Scores" << endl;
for (int i = 0; i < 15; i++)
{
|
output " Student Number DOB Student Scores\n"
Then start a loop of the following code, loop 15 times.
E
1 2 3
|
cout << aStudent.number << "\t\t" << aStudent.dob.day <<"/" <<aStudent.dob.month <<"/" << aStudent.dob.year <<"\t"<<
aStudent.scores[0] << aStudent.scores[1] << aStudent.scores[2] << aStudent.scores[3]<< aStudent.scores[4] << aStudent.scores[5]<< endl;
}
|
(edit, lol) we now input the next bits into our variables without outputting them. 15 times.
F
infile.close();
And now we close infile, please note that this is within your while loop, so infile.eof() will return true next turn, or segfault. So you can't read more data from the file here.