相关代码 |
|
例10.8 在例10.7的基础上,增加重载流提取运算符“>>”,用“cin>>”输入复数,用“cout #include using namespace std; class Complex {public: friend ostream& operator friend istream& operator >> (istream&,Complex&); //声明重载运算符“>>” private: double real; double imag; }; ostream& operator {output return output; } istream& operator >> (istream& input,Complex& c) //定义重载运算符“>>” {cout input>>c.real>>c.imag; return input; } int main( ) {Complex c1,c2; cin>>c1>>c2; cout cout return 0; }
相关资源 |
|