关于c++exception和what的问题?
#include<iostream>
#include <exception>
int main()
{
using namespace std;
//cin.exceptions(ios_base::failbit);
cout<<"Enter numbers: ";
int sum = 0;
int input;
try{
while(cin>>input)
{
sum += input;
}
} catch(ios_base::failure & bf)
{
cout<<bf.what()<<endl;
cout<<"O! the horror!\n";
}
cout<<"Last value entered = "<<input<<endl;
cout<<"Sum = "<<sum<<endl;
return 0;
}
想问下大伙为什么去掉注释那句和不去掉注释那句结果会不同 ?? 最好帮我解释下这个程序 谢谢了
还有那个what()和exception方法有什么作用? 谁能帮我解释下 我是新手 谢谢帮忙……