# 今天又解决了一个问题。

#include<iostream.h>
//using namespace std;
typedef struct
{   int x,y,z;   //为什么不能用typedef
}time;
time operator++(struct &time,struct &time)/*编译的时候老是这里出错*/
{ time time3;
int x,y,z;
time3.x=time1.x+time2.x;
time3.y=time1.y+time2.y;
tine3.z=time1.z+time2.z;
z= time3.z;y= time3.y;x= time3.x;
time3.z%=60;
time3.y=(time3.y+z/60)%60;
time3.x=(time3.x+(y+z/60)/60)%24;
return time3;
}
int main ()
{  time time1,time2,time3;

cin>>time1.x>>time1.y>>time1.z>>endl;
cin>>time2.x>>time2.y>>time2.z>>endl;
time3=time1++time2;
cout<<"the result is :"<<time3.x<<"/"<<time3.y<<"/"<<time3.z<<endl;
return 0;

}

time operator + (struct &time,struct &time) /*编译的时候老是这里出错*/

cin>>time1.x>>time1.y>>time1.z>>endl;后面不能有endl.

#include<iostream.h>
//using namespace std;
struct time
{  public:   //比原来的程序多的地方，这是为什么呢？
int x,y,z;
};
time operator+(time & time1,time & time2)//编译的时候老是这里出错，这里的＋能不能写成＋＋？回答是否定的。不可以。
{ time time3;
int x,y,z;
time3.x=time1.x+time2.x;
time3.y=time1.y+time2.y;
time3.z=time1.z+time2.z;
z= time3.z;y= time3.y;x= time3.x;
time3.z%=60;
time3.y=(time3.y+z/60)%60;
time3.x=(time3.x+(y+z/60)/60)%24;
return time3;
}
int main ()
{  time time1,time2,time3;

cin>>time1.x>>time1.y>>time1.z;
cin>>time2.x>>time2.y>>time2.z;
time3=time1+time2;
cout<<"the result is :"<<time3.x<<"/"<<time3.y<<"/"<<time3.z<<endl;
return 0;

}

• 本文已收录于以下专栏：

举报原因： 您举报文章：今天又解决了一个问题。 色情 政治 抄袭 广告 招聘 骂人 其他 (最多只允许输入30个字)