#include
using namespace std;
class Time
{
private:
int hour;
int minute;
int second;
public:
Time(int h=0,int m=0, int s=0):hour(h),minute(m),second(s){}
Time operator+(Time x)
{
Time z;
z.hour=hour+x.hour;
z.minute=minute+x.minute;
z.second=second+x.second;
return z;
}
friend istream &operator>>(istream &in, Time &z);
friend ostream &operator<<(ostream &out, Time &z);
};
istream &operator>>(istream &in, Time &z)
{
in>>z.hour>>":">>z.minute>>":">>z.second;
if(!in)
z=Time(); //如果失敗,默認初始化
return in;
}
ostream &operator<<(ostream &out, Time &z)
{
out<
return out;
}
int main()
{
Time time1,time2,time3;
cin>>time1>>time2;
time3=time1+time2;
cout<<time3<<endl;
system("PAUSE");
return 0;
}
錯誤 1 error C2679: 二進制“>>”: 沒有找到接受“const char [2]”類型的右操作數的運算符(或沒有可接受的轉換) e:\project\3-33\3-33\main.cpp 24
http://codepad.org/8tG9x0eK