Working on solving a simple problem in C++, want to understand how I could use vector of objects of user defined class type without fixed(worst case) number of elements allo
You can just declare your vector first:
vector<grades> students;
And then read the values, while pushing elements in the vector:
while(!infile.eof())
{
grades student;
infile >> student.mName;
infile >> student.mSurname;
infile >> student.mAge;
infile >> student.mLocation;
infile >> student.mMarks;
students.push_back(student);
}
You don't need no_of_records
anymore, since the number of records will be students.size()
.