problem in solving "C4996" error
-
Sir, I need to create "string" as an output using my formatted data. To achieve this I did make use of "sprintf" function.But when building a solution using visual studio I get "C4996" error. Here is the error message which I get:
Quote:
Severity Code Description Project File Line Error C4996 'sprintf': This function or variable may be unsafe. Consider using sprintf_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details. 155
to disable all depreciation I've used this preprocessors as per my compiler's suggestion
#define _CRT_SECURE_NO_DEPRECATE
#define _CRT_SECURE_NO_WARNINGS:confused: but still the error persists.I have also decreased the warning level. Kindly help me.
-
Sir, I need to create "string" as an output using my formatted data. To achieve this I did make use of "sprintf" function.But when building a solution using visual studio I get "C4996" error. Here is the error message which I get:
Quote:
Severity Code Description Project File Line Error C4996 'sprintf': This function or variable may be unsafe. Consider using sprintf_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details. 155
to disable all depreciation I've used this preprocessors as per my compiler's suggestion
#define _CRT_SECURE_NO_DEPRECATE
#define _CRT_SECURE_NO_WARNINGS:confused: but still the error persists.I have also decreased the warning level. Kindly help me.
_CRT_SECURE_NO_WARNINGS
must be defined before the header files that use the macro are included. So put it on top of your source file before including any header files. To set it for all files of a project, add it on top of stdafx.h (when using that) or add it to the preprocessor definitions of your project settings (Configuration Properties - C++ - Preprocessor - Preprocessor Definitions). Decreasing the warning level does not help here because the warning is treated as an error. To treat them as warnings, set SDL Checks to No in your project settings (Configuration Properties - C++ - General). Another option is disabling the warning by using a pragma statement:#pragma warning(disable : 4996)
This is useful when using those deprecated functions only a few times because they can be disabled on function level:
#pragma warning(disable : 4996)
void SomeFunc()
{
// Uses deprecated functions here
}
#pragma warning(enable : 4996) -
Sir, I need to create "string" as an output using my formatted data. To achieve this I did make use of "sprintf" function.But when building a solution using visual studio I get "C4996" error. Here is the error message which I get:
Quote:
Severity Code Description Project File Line Error C4996 'sprintf': This function or variable may be unsafe. Consider using sprintf_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details. 155
to disable all depreciation I've used this preprocessors as per my compiler's suggestion
#define _CRT_SECURE_NO_DEPRECATE
#define _CRT_SECURE_NO_WARNINGS:confused: but still the error persists.I have also decreased the warning level. Kindly help me.
-
_CRT_SECURE_NO_WARNINGS
must be defined before the header files that use the macro are included. So put it on top of your source file before including any header files. To set it for all files of a project, add it on top of stdafx.h (when using that) or add it to the preprocessor definitions of your project settings (Configuration Properties - C++ - Preprocessor - Preprocessor Definitions). Decreasing the warning level does not help here because the warning is treated as an error. To treat them as warnings, set SDL Checks to No in your project settings (Configuration Properties - C++ - General). Another option is disabling the warning by using a pragma statement:#pragma warning(disable : 4996)
This is useful when using those deprecated functions only a few times because they can be disabled on function level:
#pragma warning(disable : 4996)
void SomeFunc()
{
// Uses deprecated functions here
}
#pragma warning(enable : 4996) -
A better solution would be to do what the message says and use the
sprintf_s
function to create formatted strings. Or even to use the STL libraries if this is C++.