Compilation error in Visual Studio (VS): Error C4996 'sprintf': This function or variable may be unsafe. Consider using

Problem: When compiling with Visual Studio2019, an error message is reported: 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. INF_Edge_Detection D:\Code\C++ \INF_Edge_Detection\Otus_1.cpp 66

As shown below:

insert image description here

This error message is a compiler warning that the sprintf function being used may be unsafe. The compiler recommends that you use the sprintf_s function instead of the sprintf function. If you wish to disable this warning, you can define the macro _CRT_SECURE_NO_WARNINGS in your code .

#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>

Another way to solve this problem is to add macros to the properties. The specific operation steps are as follows:

insert image description here

insert image description here

Enter the following two statements in the open traversal box:

_CRT_SECURE_NO_DEPRECATE
_SCL_SECURE_NO_DEPRECATE

insert image description here
insert image description here

After adding it, run the compilation again to solve the problem, rush!

Guess you like

Origin blog.csdn.net/qq_40280673/article/details/131456198