Code:
#include <iostream>
#include <cstdlib>
#include <fstream>
#include <vector>
using namespace std;
struct stud
{
string lastname;
string firstname;
float mid;
float final;
vector<double> homework;
};
int main()
{
ifstream marks("students.txt");
int tempHW(0);
stud tempstud;
vector<stud> class1;
while (marks >> tempstud.lastname)
{
marks >> tempstud.firstname;
marks >> tempstud.mid;
marks >> tempstud.final;
marks >> tempHW;
while (tempHW != -1)
{
tempstud.homework.push_back(tempHW);
marks >> tempHW;
}
class1.push_back(tempstud);
}
for(unsigned i=0; i != class1.size(); ++i)
{
cout<<class1[i].lastname<<" "<<
class1[i].firstname<<" "<<
class1[i].final<<" "<<
class1[i].mid<<" ";
for(unsigned j = 0; j != class1[i].homework.size(); ++j)
{
cout<<class1[i].homework[j]<<" ";
}
cout<<endl;
}
system("PAUSE");
return 0;
}