The newline character remains in standard input as the >> char
consumes the users single character response only. When std::getline()
is next invoked it reads the newline character; a blank line. Consume, or skip, the newline character before asking the user for the name again:
#include <limits> // for 'std::numeric_limits'
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n')