A problem with cin after a getline makes my while loop never end at the second iteration in c++ [duplicate]

  buffer, c++, getline, while-loop

If I replace the getline for a cin, just as a test, it works as I want. But the moment I introduce the getline it creates a never-ending loop at the second iteration. I think it has something to be with the buffer but I don’t know how it works so I need help.

This is the code:

while(true)
 {
      alumno++;
     cout<<"Alumno "<<alumno<<":"<<endl;
     getline(cin,nombre_alumno);
     if(nombre_alumno == "EXIT")break;

     cin>>nota;

 }

Source: Windows Questions C++

LEAVE A COMMENT