In theory, sure. In practice, it's dicey because in_avail() isn't required to return a meaningful result. In fact, at least one popular implementation always returns 0. The most common suggestion for clearing an interactive stream buffer is:
Code:
#include <iostream> // For cin
#include <ios> // For streamsize
#include <limits> // For numeric_limits
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
I've delved deeply into "flushing" the input stream and posted my results
here. Several common yet incorrect solutions are described.