string GetTime() { time_t Timev; struct tm * TimeInformation; time(&(time_t)Timev); (tm*)TimeInformation = localtime(&(time_t)Timev); char Timec[100]; strftime((char*)Timec, 100, "[%X]:", (tm*)TimeInformation); string GetTimex((char*)Timec); return GetTimex; }; Why do I get the warning
warning C4996: 'localtime': This function or variable may be unsafe. Consider using localtime_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS.
Is there any other way to get time in format [Hour:Minutes:Second], and is it possible to shorten the code like int abc; abc=123 to int abc{123}?
localtime()function is not thread-safe; it returns a pointer to static data. Usinglocaltime_s()as the error suggests avoids that problem; you provide the storage for the result. You could usetime_t Timev = time(0); struct tm *TimeInformation = localtime(&Timev);and you should be able to avoid the named string variable too.Timevfromtime_ttotime_tand ofTimecfromchar[]tochar*? That really makes your code hard to read! Also, there's noGetTimex()in any standard library header, so you might want to explain what that is.GetTimexis a badly-namedstd::stringwith a weird initialization syntax.Get...at the front of the name!return Timec;would have been much clearer.