【发布时间】:2015-02-01 17:58:42
【问题描述】:
我正在尝试使用ctime,但我一生都无法弄清楚如何打印距当前日期 X 天的日期。到目前为止,这是我的程序:
#include "header.h"
int main()
{
time_t current;
struct tm * timedata;
time(¤t);
timedata = localtime(¤t);
cout << "The current date and time is: " << asctime(timedata) << endl << endl;
return 0;
}
如果我是正确的,time(&current) 会返回从 2000 年 1 月 1 日开始的秒数,但我得到的数字似乎太小了,不能这样。感谢所有帮助。
【问题讨论】:
-
那么你得到了什么数字?你在哪里添加
Xdays?