Jaya madhu
Jaya madhu

Reputation: 27

C++ program to get the current time

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

Answers (2)

eerorika
eerorika

Reputation: 238351

You can use std::chrono::system_clock::now() function to get the current time point.

Upvotes: 4

mkag
mkag

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

Related Questions