I am new to C++ and I am currently exploring things. Now I am on reading a text file. This is the code:
while (myfile.good()) {
        myfile >> tempNum;
        getline(myfile, tempName);
        getline(myfile, tempCourse);
        myfile >> tempTuition;
        if (myfile.eof()) break;
        Student temp(tempNum, tempName, tempCourse, tempTuition);
        students.push_back(temp);
    }
Now my file currently contains this:
201699856
Justin Chu
BSITDA
36889
Problem is, with my current code, it reads like this.
- tempNum = 201699856
- tempName = ""
- tempCourse = "Justin Chu"
- tempTuition = "BSITDA"
At tempTuition, my program freezes because it contains an invalid data. Why is the getline() skipping the 2nd line? And how can I fix the program to read correctly?
 
     
     
    