質問

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