Another newbie question here. What's the difference between these two?
cin.ignore(cin.rdbuf()->in_avail(), '\n');
cin.ignore(numeric_limits<streamsize>::max(), '\n');
I understand that the former will ignore only the characters left in the stream buffer, while the latter tries to ignore characters equal to the size of the buffer. So the end result should, normally, be the same. But then my question is why, when used in this function, the former explodes (infinite loop of "Invalid selection.\n") and the latter works fine?
int mainMenu(){
int pick=0;
cout<<"\n\nPlease make your selection:\n\n"<<
"\t1) New game\n"<<
"\t2) Options\n"<<
"\t3) Quit\n\n";
while (!pick){
cin>>pick;
if (pick>0 && pick<4) return(pick);
else pick=0;
if (!cin.good()){ //Clear mangled input
cin.clear();
cin.ignore(numeric_limits<streamsize>::max(), '\n'); //This works, in_avail doesn't.
}
cout<<"Invalid selection.\n";
}
}
I'm using code somewhat above my understanding here. What exactly is rdbuf()->in_avail() returning when std::cin has been clobbered?