求大神看看出了神马问题,再Xcode写的
在xcode里运行时抓不住错误,在vc里可以正常显示#include <iostream>
using namespace std;
int main(int argc, const char * argv[]) {
// insert code here...
int ReturnCode = 0;
cin.exceptions(cin.failbit);
try {
float Dividend=0;
cout << "Dividend: ";
cin >> Dividend;
float Divisor =1;
cout << "Divisor: ";
cin >> Divisor;
float Result = (Dividend/Divisor);
cout << Result << endl;
}
catch (...)
{
cout <<
"Input error, not a number?"
<< endl;
cin.clear();
char Badinput[5];
cin >> Badinput;
ReturnCode=1;
}
char StopCharacter;
cout << endl << "Press a key and \"Enter\":" ;
cin >> StopCharacter;
return ReturnCode;
}
输入输出
Dividend: a
Divisor: 0
Press a key and "Enter":