为什么我的cin在下面跳过?cin在跳过时
int main() {
int option;
cin >> option;
while(!cin.good()) {
cout << "Looping" << endl;
cin >> option;
}
}
为什么我的cin在下面跳过?cin在跳过时
int main() {
int option;
cin >> option;
while(!cin.good()) {
cout << "Looping" << endl;
cin >> option;
}
}
iostream中的错误很粘。在cin
再次工作之前,您需要清除错误状态。
int main() {
int option;
cin >> option;
while(!cin.good()) {
cout << "Looping" << endl;
cin.clear(); // ignore erroneous line of input:
cin.ignore(numeric_limits<streamsize>::max(), '\n');
cin >> option;
}
}
menu.cpp:在成员函数'int notekeeper :: menu :: getOption()'中: menu.cpp:27:error:从'int(*)()throw()'转换为'std :: streamsize ' menu.cpp:27:error:初始化参数1'std :: basic_istream <_CharT,_Traits>&std :: basic_istream <_CharT,_Traits> :: ignore(std :: streamsize,typename _Traits :: int_type)[ with _CharT = char,_Traits = std :: char_traits
@ will:'max'是一个函数;注意它后面的括号。 – Potatoswatter 2010-10-08 17:32:01
你不是在输入一封信,是吗? – JoshD 2010-10-07 06:46:44
我期望停下来让你输入,但它只是做了LoopingLoopingLooping等我已经试过这个在cygwin vista和g ++ ubuntu linux上。 – Will 2010-10-07 06:46:53