View Single Post
Old May 31st, 2006, 4:01 PM   #13
Narue
Professional Programmer
 
Narue's Avatar
 
Join Date: Sep 2005
Posts: 419
Rep Power: 4 Narue is on a distinguished road
>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():
// Loop
char ch;
while ( cin.get ( ch ) && ch != '\n' )
  ;

// Ignore
#include <ios>
#include <limits>
cin.ignore ( numeric_limits<streamsize>::max(), '\n' );
__________________
Even if the voices aren't real, they have some pretty good ideas.
Narue is offline   Reply With Quote