I have seen quite a number of related posts, but did not get an answer to the following question.
Consider:
char buffer[4];
cin.getline(buffer, 4);
cout << buffer << endl;
cin.getline(buffer, 4);
cout << buffer << endl;
If I enter abc
on input, I am given a chance to enter the second line and both lines appear correctly in the output. However, if I enter abcd
or, for that matter, anything longer than three characters, I do not get to enter the second line and the second line of output is empty. What exactly is going on?