getline cin is being skipped 1

getline cin is being skipped

// The reason getline is not getting user input is because
// getline does not remove new lines from the buffer.
// Before calling getline(), use cin.ignore() to clear the buffer

getline(std::cin, str);

Here is what the above code is Doing:
1. cin.ignore() is called to clear the buffer.
2. getline() is called to get user input.

Similar Posts