#include<iostream>#include<string>usingnamespace std;intmain(){int i, j;
cin>>i>>j;if(j==0)throwruntime_error("divisor is 0");
cout<<i/j<<endl;system("pause");return0;}
#include<iostream>#include<string>usingnamespace std;intmain(){for(int i, j; cout <<"Input two integers:\n", cin >> i >> j;){try{if(j ==0)throwruntime_error("divisor is 0");
cout << i / j << endl;}catch(runtime_error err){//打印异常内容并判断是否重新输入,err是runtime_error类的一个实例
cout << err.what()<<"\nTry again? Enter y or n"<< endl;//\n表示换行char c;
cin >> c;//输入y或者nif(!cin || c =='n')//没有输入或者输入为n,退出for循环break;}}system("pause");return0;}