Possible reason is myStudent array index out of bound, beause size of myStudent and numberOfLine handled seperately, its possible for numberOfLine exceed size of myStudent
//
#include <string>
#include <iostream>
#include <fstream>
#include <cstdlib>
#include <sstream>
#include "Assignment1.h"
//-----------------------------variables
//-----------------------------main body
int main()
{
cout << "Welcome to the GradeCaculator Deluxe." << endl;
GetStudentList ();
}//end main
//--------GetStudentList
string GetStudentList()
{
string FirstName;
string LastName;
int StudentId;
// int NumberOfGrades = 0;
string ClassName;
char Grade;
int CreditHour;
ifstream StudentFile;
string Course;
string StudentTextFile;
string ClassHoursTextFile;
string DataTextFile;
int NumberOfLines = 0;
string Line;
//const int StudentRecs = 20;
//student MyStudents[StudentRecs];
//const int GradeRecs = 15;
//grades MyGrades[GradeRecs];
//Get file name for the students file and open it
cout << "Enter the name of the STUDENT file including the extension :: " << endl;
getline (cin, StudentTextFile);
StudentFile.open(StudentTextFile.c_str());
if(!StudentFile.is_open())
{
exit(EXIT_FAILURE);
}
//Get file name for hours file and open it
cout << "Enter name of the CLASS HOURS file including the extension :: " << endl;
getline (cin, ClassHoursTextFile);
ifstream HoursFile;
HoursFile.open(ClassHoursTextFile.c_str());
if(!HoursFile.is_open())
{
exit(EXIT_FAILURE);
}//end if
//Get output file name and open it
cout << "Enter name of the DATA file including the extension :: " << endl;
getline (cin, DataTextFile);
ifstream OutputFile;
OutputFile.open(DataTextFile.c_str());
if(!OutputFile.is_open())
{
exit(EXIT_FAILURE);
}
//open the log file
ofstream OutLogFile;
OutLogFile.open("LogFile.txt");
if (!OutLogFile.is_open())
{
exit(EXIT_FAILURE);
}//end if
//------Get the number of lines in text file for loop control
while
(getline(StudentFile, Line))
{
++NumberOfLines;
}//end while
cout << NumberOfLines << endl;
//-----------------------------------------------------------
//StudentFile.open(StudentTextFile.c_str());
//
// for (int index1 = 0; index1 < NumberOfLines; ++index1)
// {
// StudentFile >> MyStudents[index1].FirstName
// >> MyStudents[index1].LastName
// >> MyStudents[index1].StudentId
// >> MyStudents[index1].NumberOfGrades;
// for (int index2 = 0; index2 < NumberOfGrades; ++index2)
// {
// HoursFile >> MyGrades[index2].ClassName
// >> MyGrades[index2].Grade;
// }////end inner loop
// }//end outter loop
//MyStudents[0].FirstName << endl;
}//end GetStudentList
On the same line ? After endl ? Even after turn may line into a comment ?
How about explicitly close the ftream before the function end ? I wsh I could try it myself but currently i'm not bring my laptop