Solve the problem of scanf function insecurity

Solve the problem of scanf function insecurity.

Regarding the use of vs2013 or other versions of friends, there will always be a problem at the beginning,
like the picture below
Insert picture description here

That is, for example, the scanf function. The compiler will always let you use its own defined function, saying that the scanf function is not safe, but we should still use a standard function similar to scanf, and scanf-s is only provided by this compiler Function, you cannot guarantee that it can be used in other compilers, so in order to ensure the portability and versatility of the code, we should still use the scanf function.
Next, I will provide readers with the following three methods to solve this problem:
1.
Copy the cause of this error, then intercept the _CRT_SECURE_NO_WARNINGS in it, and then define it at the beginning of the project. See the picture below
Insert picture description here
and it's all right!

Two
The second is a once and for all method.
We first open the file location of vs2013
Insert picture description here
and then click on Microsoft Visual Stdio 12.0, find the VC folder and the vcprojectitems folder under it. The
Insert picture description here
ultimate goal is to find the newc++file.cpp in the picture. , Then open it with Notepad (use notepad++ if you can’t open it), copy the previous code, save it, and it’s all right.
Insert picture description here
Then every time you create a new item, this thing will automatically appear!

Three The
third type is similar to the first type, but the code is different, because the error below is C4996, so we can also add the following code
#pragma warning(disable:4996)
Insert picture description here
can also be solved

Well, the above are the three methods I shared for you, the second of which is better, to solve this problem once and for all. I hope my article can help you who read it.
Forge ahead to C language!

Guess you like

Origin blog.csdn.net/weixin_51306225/article/details/112674520