Will someone please tell me why this dosn't work?

I'm getting tired of not being able to write robust code that catches for these simple errors. All i want to do is clear the cin.buffer. Is that too hard to ask?

The following code does not work, and I'm told that it should. (That I want to use cin.peek();)

1
2
3
4
5
6
7
8
    char a, b = 0;
    do
        {
            a = cin.peek();
            if (a != b)
                cin.ignore(a);

        }while (a != b);
bump
cin.ignore()'s first parameter is the number of characters to ignore. This will implictly cast a to an int then ignore that many characters...try using 1 instead.
Topic archived. No new replies allowed.