The problem is that
std::cin>> and
std::getline don't mix well.
When
std::cin>> gets input it reads the entire line including the newline character (the character when you hit enter/return on the keyboard.)
Inside the buffer would contain all the characters for your input as well as the newline character. So if you entered the number 1 for example inside the input buffer would be:
std::cin>> then strips the all the values upto but not including the first white space character which in this case is the newline.
So
std::cin>> places "1" into the variable, and the rest of the buffer remains for the next
std::cin call.
When
std::getline() is called with
std::cin it first checks the input buffer for remaining characters up to and INCLUDING the newline character. Now take that into context with my previous example. In the buffer there is still a newline character!
std::getline sees that, and immediately places nothing into the string and ends its operation. To avoid this issue you need to make sure the buffer is empty before running a
std::getline() operation. The way to do this is with a
cin.ignore() call before
std::getline().
Place this before the std::getline() in your program:
cin.ignore(0x7FFFFFFF, '\n'); // This removes everything in the buffer up to the last '\n' character.
That will fix that
std::getline() closing out without any input.