int main() { int temp; while (cin>>temp, !cin.eof()) { if (cin.bad()) { throw r
Because your loop will end only when end-of-file is reached. But if you try to read a number where there is an alpha character, cin will fail but eof will never be reached. It will fail to read the number over and over again.