📄 12_4.cpp
字号:
#include <iostream>
#include <cmath>
using namespace std;
double dsqrt(double d){ if(d<0) throw 1; return sqrt(d);}//抛出异常
int main()
{ int x;
while(1)
{ cout<<"Please input a positive integer:"; cin>>x;
try {cout<<dsqrt(x)<<endl; }
catch(int) {cout<<"It is a negtive integer"<<endl; }//捕捉异常
if(x<0) break;
}
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -