My teacher was saying I didn't have to delete my pointers in this case since I was in the main. But I'm trying to understand why my pointers wouldn't delete regardless. The code is failing where I have it in bold. I get a Debug Assertion Failed error.
int main()
{
ifstream fin;
int sizeA;
fin.open("courses.txt");
if (fin.fail())
{
cerr << "Open Failure\n\n";
system("pause");
exit(1);
}
fin >> sizeA;
fin.ignore();
Student *list = new Student[sizeA];
for (int ct = 0; ct < sizeA; ct++)
{
getline(fin, list[ct].name);
fin >> list[ct].ncourses;
list[ct].courses = new string[list[ct].ncourses];
for (int k = 0; k < list[ct].ncourses; k++)
fin >> list[ct].courses[k];
fin.ignore();
}
fin.close();
cout << "Enter menu choice or Q to quit:\n";
cout << "D to display all students and courses\n";
cout << "S to display courses for a student\n";
cout << "C to diplay students taking a course\n\n\n";
menu(list, sizeA);
for (int i = 0; i < sizeA; ++i)
delete list[i].courses;
delete list;
cout << endl;
return 0 << system("pause");
}