Your studentfile
is most likely in a fail state, as you never check whether the read operations are successful or not. Change the code as follows:
if(!(studentFile >> ssn >> resident >> hours))
{
std::cout << "read failed";
return 1;
}
//...
do
{
// Do stuff
// REMOVE THIS LINE: studentFile >> ssn >> subTuition;
} while (studentFile >> ssn >> subTuition); // while loop stops as soon as read fails
The key lesson to learn here is always perform error checking during read and write operations.
Also, please read Why is iostream::eof inside a loop condition considered wrong? as while (!studentFile.eof())
is considered a C++ anti-pattern.
solved Unable to find cause of infinite loop [closed]