爲什麼我的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