C++ if(!cin) causes loop
问题 I tried to use if(!cin) to validate if the user input really is an integer. However my programm then just goes into an infinite loop never asking vor new input do{ cin >> temp->data; if(!cin){ cout << "Please enter a Number!" << '\n'; correct=false; } }while(correct==false); Would be great if someone could help me :) 回答1: When std::cin fails to read the input, the appropriate error flags are set. Therefore you want to reset the flags using std::cin.clear() so that the next input operation