首页 > 手机 > vivo > 有300的微信群红包,怎么做二维码图片分享给你们

有300的微信群红包,怎么做二维码图片分享给你们

来源:http://www.codepub.com 时间:2022-02-06 12:25:24 编辑:yyzn 手机版

给你看个例子就明白了。你自定义的类,只要是你重载了<<。则都可以输出的。 //重载输出运算符<< #include //有些编译系统可能是包含iostream,并指明名字空间std; using namespace std; class CComplex { public: CComplex(){ real = 0.0; image = 0.0; } CComplex(double rv) { real = rv; image = 0.0; } CComplex(double rv,double iv) { real = rv; image =iv;} friend CComplex operator + (CComplex c1,CComplex c2); //作为类的友元函数,重载加运算符, friend ostream& operator<<(ostream& stream,CComplex c); //重载输出运算符<< ~CComplex() {}; private: double real; //复数的实部 double image; //复数的虚部 }; CComplex operator +( CComplex c1,CComplex c2) { CComplex temp; temp.real = c1.real + c2.real; temp.image = c1.image + c2.image; return temp; } ostream& operator<<(ostream &stream, CComplex c) { stream<<(<<c.real<<+<<c.image<<i)<<endl; //以(a+bi)的格式输出复数 return stream; } int main( ) { CComplex c1(1,5),c2(3); cout<<c1=<<c1; //使用重载输出运算符<<,输出复数c1 cout<<c2=<<c2; //使用重载输出运算符<<,输出复数c2 c1 = c2+16; cout<<执行语句c1 = c2+16;之后,; cout<<c1=<<c1; return 0; }

文章TAG:二维码红包你们

最近更新