I have an annoying problem with this piece of code:
int len = 5;
char str[5];
do {
cout << "Enter a string: ";
cin.getline(str, len);
} while (true);
when the length of str is less than 5, the code runs fine. I can re-enter the string over and over. But when I enter a string with the length greater than 5, the loop repeats forever without letting me to enter the string. So what is the problem here?