know that a classmate of mine has already posted a similar question on this topic ,but i still cant wrap my mind around how this is supposed to work. This is the file setup that contains fake student information:
918273645,Steve,Albright,ITCS2530,MATH210,ENG140
123456789,Kim,Murphy,ITCS2530,MATH101
213456789,Dean,Bowers,ITCS2530,ENG140
219834765,Jerry,Clark,MGMT201,MATH210
For some reason i am only able to read the first line of the text file and not any of the lines below. I need to figure out how to read the first 9 characters of each line and compare them to the users input. Then carry over the rest of that line. but cant figure out where I'm going wrong.
This is what i have so far:
void Login()
{
Student NewStudent;
ifstream inFile;
ifstream outFile;
string inFileName = "C:\\Users\\Prophet\\Desktop\\registration.txt";
string outFileName = "C:\\Users\\Prophet\\Desktop\\registration.txt";
openInputFile(inFile, inFileName);
while (true)
{
cout << "Please enter your student ID\n" << endl;
cin >> NewStudent.StudentID;
if (NewStudent.StudentID.length() == 9)
break;
else
cout << "That ID is invalid - IDs are 9 digits" << endl;
}
if (inFile.is_open())
{
while (!inFile.eof())
{
string line;
while (getline(inFile, line))
{
stringstream ss(line);
string StudentID, FirstName, LastName, ListOfCourses;
getline(ss, StudentID, ',');
getline(ss, FirstName, ',');
getline(ss, LastName, ',');
getline(ss, ListOfCourses, ',');
cout << "\n";
{
if (StudentID == NewStudent.StudentID)
{
cout << "Welcome to the Macomb Community College enrolment system " << FirstName << " " << LastName << endl;
inFile.close();
MainMenu();
}
if (StudentID != NewStudent.StudentID)
{
cout << "Welcome New student" << endl;
cout << "Please enter yuour first name: ";
cin >> NewStudent.FirstName;
cout << "Please enter yuour last name: ";
cin >> NewStudent.LastName;
outFile.open("C:\\Users\\Prophet\\Desktop\\registration.txt");
openOutputFile(outFile, outFileName);
MainMenu();
}
}
}
}
}
}