Disabling Warnings generated via _CRT_SECURE_NO_DEPRECATE
What is the best way to disable the warnings generated via _CRT_SECURE_NO_DEPRECATE
that allows them to be reinstated with ease and will work across Visual Studio versions?
Solution 1:
If you don't want to pollute your source code (after all this warning presents only with Microsoft compiler), add _CRT_SECURE_NO_WARNINGS
symbol to your project settings via "Project"->"Properties"->"Configuration properties"->"C/C++"->"Preprocessor"->"Preprocessor definitions".
Also you can define it just before you include a header file which generates this warning. You should add something like this
#ifdef _MSC_VER
#define _CRT_SECURE_NO_WARNINGS
#endif
And just a small remark, make sure you understand what this warning stands for, and maybe, if you don't intend to use other compilers than MSVC, consider using safer version of functions i.e. strcpy_s instead of strcpy.
Solution 2:
You could disable the warnings temporarily in places where they appear by using
#pragma warning(push)
#pragma warning(disable: warning-code) //4996 for _CRT_SECURE_NO_WARNINGS equivalent
// deprecated code here
#pragma warning(pop)
so you don't disable all warnings, which can be harmful at times.