View Single Post
Old Jun 1st, 2006, 2:10 PM   #17
Cache
Hobbyist
 
Join Date: Sep 2005
Posts: 263
Rep Power: 4 Cache is on a distinguished road
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.
Cache is offline   Reply With Quote