Quote:
|
Originally Posted by Narue
>Try clearing the stream by using 'cin.sync();' before 'cin.get();'.
Um, no. cin.sync() isn't guaranteed to do anything meaningful, much less "clear" the stream. The only portable way to read and discard leftover characters is to read them either with a loop, or with cin.ignore():
|
Quote:
|
Originally Posted by DaWei
Note that the extraction function will return if it finds an item eligible to be returned or one that causes an error. "I have to call it twice (or ten times, or whatever)" is not a valid solution to offer. There are reasons for these things. Voodoo is okay, but hard on one's chickens.
|
I see. This harks back to one of my first threads on this forum when I was just starting to learn C++. I was first told to "try flushing it" (the stream). Then told to use cin.sync(), and it "worked". Guess I made the assumption that cin.sync() was clearing the stream and never thought any more of it.
Just for reference:
http://www.programmingforums.org/for...ead.php?t=6640
Won't be making that mistake again.
