Click here to Skip to main content
15,887,083 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Error is:
Error C4996 'ctime': This function or variable may be unsafe. Consider using ctime_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.

What I have tried:

#include<iostream>
#include<ctime>
using namespace std;
int main()
{
	time_t now = time(0);
	//Convert time to string form
	char *tm = ctime(&now);
	cout << "Time of System is: " << tm << endl;
	system("pause");
	return 0;
}<pre>
Posted
Updated 12-May-18 21:41pm

It's not an error, it's a warning. You are using an outdated function (it's been Depreciated[^] ) and it's suggesting a more modern version: ctime, ctime_s - cppreference.com[^]
You can ignore it for a simple program like this, or use the newer code.
 
Share this answer
 
Comments
Member 13817351 13-May-18 2:40am    
I need it for a project. In which i want to find age of employee from his date of birth. If you correct this warning and resend me. I don't know what to do. This program is not part of project. Here i just want to know the concept.
Member 13817351 13-May-18 2:42am    
When i run the program it says unable to start program.
CPallini 13-May-18 7:15am    
It runs fine on my Windows 8.1 OS (Visual Studio 2012).

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900