output管一个复数的输出,return之后再输出其它的复数
input同理
#include <iostream>
using namespace std;
class Complex {
public:
friend ostream & operator << (ostream &,Complex);
friend istream & operator >> (istream &,Complex &);
private:
double real,imag;
};
ostream& operator << (ostream &output,Complex c) {
output<<'('<<c.real<<','<<c.imag<<"i)"<<endl;
return output;
}
istream& operator >> (istream &input,Complex &c) {
input>>c.real>>c.imag;
return input;
}
int main()
{
Complex c1,c2;
cin>>c1>>c2;
cout<<c1<<c2;
return 0;
}