Clock function error

**Why is it that when i use ctime to capture the time I am getting this error:

time_t
now = time(0);// convert now to string form
char* dt = ctime(&now);
cout << "The local date and time is: " << dt << endl;

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.
**
Last edited on
Because Microsoft is absolutely EVIL and wants you to use its non-portable code.

Do you have a "warnings as errors" flag set anywhere?

-Albatross
I think that's just visual studio.

Don't think ctime_s is standard tho. Perhaps get another compiler like TDM-GCC or rubenVB's C++ compiler.
yes i have #define _CRT_SECURE_NO_WARNINGS
but visual is still giving me error warning, any other way to capture the clock in C++?
Well...

There is the entire <chrono> header in C++11. However, you might find it a bit intimidating.

What gets me is that it's giving you an error instead of a warning. That code is standard C++ and the last time I used visual studio (which I admit was years ago), it gave its "unsafe" warnings as just that, warnings. I know Visual Studio has a "warnings as errors" flag somewhere, and I can't help but wonder if it might be set.

You could get another compiler, of course, like Bourgond Aries suggested. I can't make any assertions as to whether the generated executables will be of a higher or lower quality than from Microsoft's compiler, but the differences shouldn't be glaringly large.

-Albatross
Topic archived. No new replies allowed.