# include & lt; Windows. H>
# include & lt; Stdio. H>
# include & lt; Stdlib. H>
# include & lt; String>
# include & lt; Time. H>
using namespace std;
Char * GetCurTimestring ()
{
Char w_content [64].
SYSTEMTIME Tm;
GetLocalTime (& amp; Tm);
Memset (w_content, 0, sizeof (w_content));
Sprintf_s (w_content "% % 4 d/02 d 02/02 % d % d: % 02 d: % 02 d. % 3 d", Tm. WYear, Tm. WMonth,
Tm. WDay, Tm wHour, Tm. WMinute, Tm. WSecond, Tm. WMilliseconds);
//char * strCurTime=w_content;
//char * T=new char [64].
//strcpy_s (T, 64, strCurTime);
//return T;
Return w_content;
}
Int main ()
{
Char * time=GetCurTimestring ();
//the following code is the code
Printf (" % s \ n ", time).
Sleep(1000);
Char * time2=GetCurTimestring ();
Printf (" % s \ n ", time2);
Sleep(1000);
Char * time3=GetCurTimestring ();
Printf (" % s \ n ", time3);
Getchar ();
return 0;
}
Vs compilation, why can only display 8 characters, the others are all gibberish, call the function to comment after is ok
CodePudding user response:
Char w_content [64]. Are comment part is on the stack memory, the memory allocated on the heap, again, your memory is not released
CodePudding user response:
the static char w_content [64].
CodePudding user response: