生活随笔
收集整理的這篇文章主要介紹了
流操作运算符(二)
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
output管一個(gè)復(fù)數(shù)的輸出,return之后再輸出其它的復(fù)數(shù)
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;
}
轉(zhuǎn)載于:https://www.cnblogs.com/xyqxyq/p/10350150.html
總結(jié)
以上是生活随笔為你收集整理的流操作运算符(二)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。