atoi related question

This is a discussion on atoi related question within the C++ Programming forums, part of the General Programming Boards category; the below program ends when a letter is input because any non numerical value is converted to 0. What if ...

#include <iostream>
using namespace std;
int main(void)
{
int i;
while (!(cin >> i ))
{
cerr <<"Bad number " << endl;
cin.clear();
while ((i = cin.get()) != '\n' && i != EOF);
}
cout <<"Number was " << i <<endl;
return(0);
}
/*
Output
abc
Bad number
1
Number was 1
0
Number was 0
567abc
Number was 567
The last run left abc in the input buffer. Is this what
you want to do when a user enters something like that?
*/