I have a function in which I want to read integers until I enter a non integer. And I want to repeat that function until I press enter. But the character gets passed to the second cin and it becomes an infinite loop.
void read () {
int x;
while ( cin >> x );
}
int main () {
char a;
do {
read ();
cin.ignore (256, '\n')
cin >> a;
} while ( a != '\n' )
}