This means that input awaiting read is pending. You can clear the input:
cin.ignore(std::numeric_limits<std::streamsize>::max(); std::getline(cin, res);
If this happens, it means that you did not read all the data from the input stream in the previous reading. The above code will destroy any user input before reading more.
This probably means that you are mixing operator>> with std::getline() to read user input. You should probably select one method and use it (std :: getline ()) throughout the application (you can mix them, you just need to be more careful and remove the "\ n" after using the → operator to make sure that the subsequent std :: getline () are not confused ..
If you want to read a number by reading a line, analyze the line number:
std::getline(cin, line); std::stringstream linestream(line); linestream >> value;
source share