[ create a new paste ] login | about

Link: http://codepad.org/8tG9x0eK    [ raw code | output | fork ]

C++, pasted on Nov 23:
#include<iostream>
#include <string>
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)
{
string sp=":";
	in>>z.hour>>sp>>z.minute>>sp>>z.second;
    if(!in)
        z=Time(); //如果失败,默认初始化
	return in;
}
ostream &operator<<(ostream &out, Time &z)
{
	out<<z.hour<<":"<<z.minute<<":"<<z.second;//错误行
	return out;
}
int main()
{
	Time time1,time2,time3;
	cin>>time1>>time2;
	time3=time1+time2;
	cout<<time3<<endl;
	system("PAUSE");
	return 0;

}


Output:
1
2
3
0:0:0

Disallowed system call: SYS_fork


Create a new paste based on this one


Comments: