0
我的代码是为什么在调用localtime()函数之前不需要malloc struct tm指针?
#include <iostream>
#include <ctime>
using namespace std;
void main()
{
time_t nowTime;
struct tm *nowStruct;
time(&nowTime);
nowStruct = localtime(&nowTime);
cout << nowStruct->tm_hour << ":" << nowStruct->tm_min << endl;
}
我怀疑那里是用来存储结构TM内存中的地址。
要补充说明,引用我的系统上的manpage:_“返回值指向一个静态分配的结构,可能会被随后调用任何日期和时间函数覆盖。”_ – moooeeeep