Reputation: 27
I have to create a simple window service program which is to be executed in visual studio using C++ language. I have used ctime
and localtime
keywords but it returns an error saying:
This function or variable may be unsafe. Consider using any other ....
I am using Visual Studio 2019
Upvotes: 0
Views: 190
Reputation: 238351
You can use std::chrono::system_clock::now()
function to get the current time point.
Upvotes: 4
Reputation: 116
ctime
and localtime
are unsafe as these returns pointer to static data.
Therefore, ctime_s
and localtime_s
are provided in VS2019 (also in some earlier versions), which takes a pre allocated pointer in which value need to be returned and hence safe to use.
Upvotes: 3