I get the same string result for curTime and pastTime when I use "ctime" even though the actual values at curTime and pastTime are different by 600 seconds.

How am I getting the same string time for both when using ctime?

thx

struct _timeb timebuffer;

_ftime(&timebuffer);

const time_t  curTime = (const time_t)timebuffer.time;
const time_t  pastTime = curTime - (const time_t)600;

s.Format("%d  %s\n%d  %s", curTime, ctime(&curTime), pastTime, ctime(&pastTime) );
MessageBox(s);
有帮助吗?

解决方案

ctime returns a string that can be statically allocated.

So one of your two calls is overwriting the string that the other one generates. You'll need to split that into two print statements, or copy (string copy) the return values of ctime into temporaries.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top