I believe many small bloggers will have such a problem when they first come into contact with the vs compiler:
Why does my scanf report an error when used in vs?
I’ll leave the reasons behind first. I’ll teach you a way to solve this problem first.
It’s very simple, just fill in the first line: #define _CRT_SECURE_NO_WARNINGS
The problem can be solved very well
But there is a question. Do we have to add such a sentence to the first line every time we create a new project?
Will it be too cumbersome?
Next, I’ll teach you a once-and-for-all method! ! !
First paste #define _CRT_SECURE_NO_WARNINGS
Find this file under this path newc++file.cpp
Then open it in Notepad and copy the code you just pasted onto it.
At this time, every time you create a project, it will automatically be added to your first line
#define _CRT_SECURE_NO_WARNINGS
Of course, some students may not be able to modify the file due to insufficient permissions newc++.file.cpp file
At this time you can copy this file on your desktop and add
#define _CRT_SECURE_NO_WARNINGS
Finally replace the original newc++.file.cpp file (Note that it is to replace < /span>)
I believe that the above explanation can solve your problem. Let me talk about the specific reasons next!
The reason is actually very simple, that is, the compiler we usevs, he thinks scanf< /span>, we are not allowed to use itdangerousThis function is too
It recommends that we use the scanf_s function.
However, I personally do not recommend using this function! ! !
This function can only be recognized on the VS compiler, and cannot be recognized on other compilers. An error will be reported and there is no compatibility.
That’s the end of this article. Thank you all for watching. See you in the next blog.