发动大家找错误(我没辙了)
下面主函数中的while循环中老是能输出1900-2-29,但1900是平年,不会有29天,而date类的构造函数中加入了处理这种情况的函数process(),主函数开始的date(1900,2,29)为什么能构建正确?难道与随机函数有关?大家帮帮我......
#include <iostream>
#include <cstdlib>
#include "date.h"
using namespace std;
using namespace zhw;
int main(void)
{
date da(1900,2,29); //为什么此处能正确构造
if(da.isError()) cout<<"\n不正确的日期\n";
cout<<da.datetostr()<<endl; //
cout<<asctime(&da)<<endl; //
/*
time_t t=0;
tm* ptr=localtime(&t); //1970.1.1
cout<<asctime(ptr); //输出1970
*/
int a,b,c,d=16000,i=0;
int e,f,g;
srand((unsigned)time(0));
while(d--)
{
a=rand()%2014;
b=rand()%13;
c=rand()%32;
e=rand()%2014;
f=rand()%13;
g=rand()%32;
date dd(a,b,c);
date ddd(e,f,g);
//dd.process();
//ddd.process();
//if(dd.isError()) cout<<"dd\n";
//if(ddd.isError()) cout<<"ddd\n";
a=difmonth(dd,ddd);
b=difmonth_t(dd,ddd);
if(a!=b)
{ //为何此处能输出1900-2-29,构造函数中加入了process的啊
cout<<dd.datetostr()<<" a:"<<a<<endl<<ddd.datetostr()
<<" "<<b<<endl<<endl;
++i;
}
}
if(0 == i)
cout<<"\n两求相差月数函数结果相等\n"<<endl;
return 0;
}
month Required. The month as an integer between 0 and 11 (January to December).
[解决办法]