【发布时间】:2015-08-26 22:39:36
【问题描述】:
为什么asctime(ptr) 什么都不返回?结构的所有变量都有值。有人可以解释为什么会这样吗?
我也尝试过使用strftime,但结果是一样的。
#include <iostream>
#include <ctime>
#include <new>
//#include <cstdio>
using namespace std;
int main(int argc,char *argv[])
{
struct tm *ptr=new struct tm;
//char buf[50];
ptr->tm_hour=0;
ptr->tm_mon=0;
ptr->tm_year=0;
ptr->tm_mday=0;
ptr->tm_sec=0;
ptr->tm_yday=0;
ptr->tm_isdst=0;
ptr->tm_min=0;
ptr->tm_wday=0;
cout << asctime(ptr);
//strftime(buf,sizeof(char)*50,"%D",ptr);
//printf("%s",buf);
return 0;
}
【问题讨论】:
-
return nothing到底是什么? -
什么都不返回是什么意思?此外,对于
tm结构的某些成员,0 不是有效值。在这种情况下,它将返回NULL。 -
mday 不能为 0 你是对的...谢谢