?搞不明白 五六行什么意思?
程序代码:
#include<fstream> #include<iostream> #include<cmath> using namespace std; class triangle;//这一行的作用是什么 ostream& operator<<(ostream& output,triangle& obj);//这一行的作用又是什么 class triangle { public: triangle(double x,double y,double z)//构造函数传参 {a=x;b=y;c=z;} friend ostream& operator<<(ostream&,triangle&);//声明运算符<< 重载为友元函数 private: double a,b,c; }; ostream& operator<<(ostream& output,triangle& obj) { double p; cout<<"三角形的各边长是:"; output<<obj.a<<" "; output<<obj.b<<" "; output<<obj.c<<" "; p=(obj.a+obj.b+obj.c)/2; output<<"三角形的面积是:"<<sqrt(p*(p-obj.a)*(p-obj.b)*(p-obj.c)); return output; } int main() { triangle c1(3,4,5); cout<<c1<<endl; return 0; }