0

「ctime」を使用すると、curTime と pastTime の実際の値が 600 秒異なっていても、curTime と pastTime で同じ文字列結果が得られます。

ctime を使用している場合、両方で同じ文字列時間を取得するにはどうすればよいですか?

どうも

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);
4

1 に答える 1

4

ctime静的に割り当てることができる文字列を返します。

したがって、2 つの呼び出しのうちの 1 つは、他の呼び出しが生成する文字列を上書きしています。これを 2 つの print ステートメントに分割するか、戻り値ctimeを一時的にコピー (文字列コピー) する必要があります。

于 2012-05-10T06:20:09.100 に答える