(c++)谁能帮我解决下这个问题,调试了好多次总是是出现问题,在此先谢过了!

2025-03-02 00:29:03
推荐回答(3个)
回答1:

这是Microsoft Visual C++ 6.0的Debug,必须修改一下,采用旧标准,如下:

#include
#include
class Time
{
public:
int hour, minute, second;
void set(int h, int m, int s)
{
hour=h, minute=m, second=s;
}
friend Time& operator++(Time& a);
friend Time operator++(Time& a, int);
friend ostream& operator<<(ostream& o,const Time& t);
} ;
Time& operator++(Time& a )
{
if(!(a.second =(a.second +1)%60) && !(a.minute =(a.minute +1)%60))
a.hour =(a.hour +1)%24;
return a;
}
Time operator++(Time& a, int){
Time t(a);
if(!(a.second =(a.second +1)%60)&&!(a.minute =(a.minute +1)%60))
a.hour =(a.hour +1)%24;
return t;
}
ostream& operator<<(ostream& o,const Time& t){
o<return o<}
int main()
{
Time t;
t.set(11,59,58);
cout<cout<<++t;
return 0;
}

回答2:

应该改成ostream& operator<<(ostream& o,const Time& t){
o<<return o;
}
setfill函数的参数是一个空字符。不是字符串。setfill(' ')单引号,且单引号内有一个空格

回答3:

friend ostream& operator<<(ostream& o,const Time& t);

操作要写在方法内