你输入非数字看看~
for( ; me.alive() ; ) { 淡泊名利,志存高远 } //Forever
#include <iostream>
#include <exception>
using namespace std;
void tryToGuess()
{
bool guessOncemore = true;
int magic=123;
int guess;
cin.exceptions(ios_base::failbit);
try
{
while(guessOncemore && cin>>guess)
{
if(guess==magic)
{
cout<<\"* * right * *\"<<endl;
guessOncemore = false;
}
else
cout<<\"* * wrong * *\"<<endl;
}
}catch(ios_base::failure & bf)
{
cout<<bf.what()<<endl;
cin.clear(); // reset stream state
while(!isspace(cin.get()))
continue; // get rid of bad input
tryToGuess(); // will work now
}
}
int main(int argc, char* argv[])
{
tryToGuess();
return 0;
}
输入123.qwqdq......
或者123.123123213.....
看看……
不过你写得不错啊,偶现在还看不懂,嘿嘿