cin.clear() doesn't reset cin object
-
30-10-2019 - |
문제
I have the following loop. It should read numbers until EndOfFile
, or the user input -999
int arr[100];
int index;
for (index = 0; index < 100; index++)
{
cin >> arr[index];
if (!cin)
{
cin.clear();
index--;
continue;
}
if (arr[index] == -999)
{
break;
}
}
When the user input an invalid thing, such as some char
s, this loop is being repeated for ever without clear
ing the error state or stopping.
올바른 솔루션이 없습니다
제휴하지 않습니다 StackOverflow