Location>code7788 >text

C4996 'scanf': This function or variable may be unsafe. Consider using scanf_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS.

Popularity:933 ℃/2024-10-04 12:58:53

Cause of error

The VS platform considers the scanf function unsafe and requires that it be replaced with the scanf_s function

prescription

Option 1: Replace scanf with scanf_s [not recommended]

Replace scanf with scanf_s

However, the scanf_s function can only be used on vs, and cannot be used on other platforms, so the modified code cannot be ported and is not recommended.

Option 2: #define _CRT_SECURE_NO_WARNINGS

Add preprocessor directive before header file #define _CRT_SECURE_NO_WARNINGS

The following method can be used to have this preprocessor directive added automatically to all subsequent projects:

Look for the newc++ file in the vs installation path and add this preprocessor directive to the first line of the file #define _CRT_SECURE_NO_WARNINGS

Method 3: Setting up the preprocessor

Right click -> Configuration Properties -> Properties -> C/C++ -> Preprocessors -> Preprocessor Definitions -> Enter_CRT_SECURE_NO_WARNINGS

Method 4: Disable security checks

Right click -> Configuration Properties -> Properties -> C/C++ -> Code Generation -> Security Checks -> Disable Security Checks (/GS-)