A stream might fail at any time & your loop has no way of reacting to it. You should do something like this :
if( programme == "Physics" )
{
filein.ignore();
// a more strict version is : (#include <limits>)
//filein.ignore( numeric_limits<streamsize>::max(), '\n' );
while( getline(filein, namephys, '*') &&
filein >> idphys &&
filein.ignore() && //** ignore the trailing newline (operator>> doesn't read it)
getline(filein, course, '*') &&
filein >> mark &&
filein.ignore() )
{
/* do something */
}
}
This loop immediately exits whenever the stream state becomes bad