我只是在異常處理方面嘗試一個示例。 我收到錯誤錯誤:'operator >>'不匹配 我的程序出了什麼問題。 我正在使用linux gcc。錯誤:'operator >>'不匹配
#include<iostream>
using namespace std;
void div(double, double);
void read (double *, double *);
main()
{
double a,b;
cout<<"enter the two nos";
cin>>a>>b;
read(&a,&b);
div(a,b);
}
void div(double a, double b)
{
double d;
try {
if(b==0)
throw "divide by zero condition occured";
d=a/b;
cout<<"divsion of two no is"<<d<<endl;
}catch(const char *e)
{
cout<<"exception is "<<e<<endl;
}
}
void read(double *a,double *b)
{
cout<<"Enter the 2 no.";
cin>>a>>b;
}
我也嘗試另一個函數讀取功能
void read(double *a,double *b)
{
double c,d;
cout<<"Enter the 2 no.";
cin>>c>>d;
a=c;
b=d;
}
,但它也有錯誤:
cannot convert ‘double’ to ‘double*’ in assignment
你可能想要在你的問題完整的錯誤消息。 –
Typo。你需要在'read'中解除'a'和'b'的引用。 – NathanOliver
通過參考。它將消除這些指針缺陷。 –