I'm taking an intro to C++, and I'm using VStudio 2013 on Win7. I try to avoid the wrong data input from my menus, and it's working in all of them except this one.
cout << "Please choose your second number" << endl;
cin >> move2;
if (move2 < 1 || move2 > size)
{
cout << "That's not a valid move" << endl;
Sleep(2000);
cin.sync();
cin.clear();
}
the only difference is that in the condition for move > a variable (size) not a number. When I enter a char it goes back to the question asking for another input, but if I enter a word, it breaks!
I try to use cin.ignore(numeric_limits<streamsize>::max(), '
');
but the compiler highlights max()
and it says "expecting identifier".
It maybe easy for all of you good programmers, but I don't know how to fix it. Can anybody help me?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…