Since this is a newbie question (though I am not a newb), I am posting this here.
I have tried:
cin.rdbuf()->in_avail();
Upon further inspection of the source code, I saw that this actually did nothing at all (except return the number of characters available to be immediately read)
while(cin.rdbuff()->in_avail()) cin.get();
Theoretically should work, but, for some reason, does not... it should get a character while there are characters to be read, but when there is a character to be read (such as a multi-byte character) it will return 0 (I tested this one thoroughly... couldn't understand it!)
cin.clear()
read about this one, but documentation reveals that it doesn't even touch the buffer (has nothing to do with it!), even though it's been suggested... (scary...)
Anyway... I don't want to read until a '\n' or EOF (i tried EOF too, doesn't work). There must be some way to tell how many characters are available for reading in the buffer. The only way I;ve been able to erase the buffer so far, is by making API calls to set input to un-buffered, and then buffered. I would rather not have to do that.
Would this work, though:
1 2 3 4
|
//I would make the value of the buffer equal to the empty buffer of a stringstream
std::stringstream ss;
(*(cin.rdbuf())) = (*(ss.rdbuf())); //set cin's buffer to that of an 'empty' one
|
I don't have the time to test it (school and all) but I would like to know.
If there is another (better) way to do this, I would also like to know about that.