Hi i've have this problem in my code when i do the overloading of operator >>. My problem for this code isnt encounter error but my input like say i input 7, the num.a output will change this 7 to 55 and num.b output for 5 to 53. below is the code.
class Complex
{
friend istream& operator>>(istream&, Complex&);
friend ostream& operator<<(ostream&, const Complex&);
public:
Complex(int a=0, int b=0) {}; // constructors
Complex operator +(Complex);
Complex operator *(Complex);
bool operator ==(const Complex&) const;
bool operator >(const Complex&) const;
private:
int a, b;
};
istream& operator>>(istream &in, Complex &num)
{
string line="";
fflush(stdin);
in>>line;
for(int i=0; i<line.length(); i++)
{
if(i==1)
{
num.a = line[i];
}
else if(i==4)
{
num.b = line[i];
}
}
return in;
}
my format of input is (7+i3). This is a complex number format. Hope to hear the reply soon.Thanks