When execution reaches getline(cin, rp. command) the program just print "Enter repo command: " and skips the getline(cin, rp. command) line so that the user is not given time to respond.
The getline() function should not leave anything behind, it extracts the end of line character and discards it, so you should not need the ignore() at all in this case.
getline(cin, newString); begins immediately reading and collecting characters into newString and continues until a newline character is encountered. The newline character is read but not stored in newString.
The getline() function in C++ is used to read a string or a line from the input stream. The getline() function does not ignore leading white space characters.
So I have a function that keeps skipping over the first getline and straight to the second one. I tried to clear the buffer but still no luck, what's going on?
void getData(char* strA, char* strB)
{
cout << "Enter String 1: "; // Shows this line
cin.clear();
cin.getline(strA, 50); // 50 is the character limit, Skipping Input
cout << endl << "Enter String 2: "; // Showing This Line
cin.clear();
cin.getline(strB, 50); // Jumps Straight to this line
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With