VS security error reporting problem - three methods to take you to solve the problem

*Reminder, the last method is to work hard, you can jump directly to the answer if you need it urgently, but you will gain something after reading it carefully

Table of contents

Error instance

Option 1: Magic_s

Solution 2: Shield Dafa

Solution 3: Mysterious code line, once and for all (ultimate move)

Problem and Solution: Cannot Change File Contents

PS: This is the first time I write a blog, please like and comment to support me, thank you all.


Example of error reporting:

Regarding vs2019 and later versions, do you often encounter some inexplicable errors in the process of using it?

for example:

When we use scanf, get, etc., will we encounter errors from VS? This is actually because of the c language compiler. The compiler that comes with VS takes into account security issues and will report errors to you. I will explain below Let's introduce the following solutions.

Option 1: Magic_s

First of all, the first method is very simple, which is to directly change scanf to scanf_s (get is the same), so that VS will not report an error. This method is simple and fast, but it also has shortcomings. The code written in this way is not portable. , and cannot be directly used on other compilation software after copying and pasting directly. Then we need our second method.

Solution 2: Shield Dafa

first look at the operation

 What it means is that if your warning number is 4996 and you write this line in the code, you can invalidate the warning error numbered 4996, and vs will not care whether your code is correct or not. But the disadvantage of this method is also obvious, that is, one line of code can only block one kind of error warning. When you need to block a lot of warnings, this method seems rather useless.

So, I will introduce the third kind—that is, the big move, which can effectively solve our problems.

Solution 3: Mysterious code line, once and for all (ultimate move)

In fact, after you were warned by vs with scanf, vs has already told us this solution. What? You do not believe? Don't talk, just watch me do it.

Have you seen it, if you want to invalidate the error, please use _CRT_SECURE_NO_WARNINGS

So how to use it specifically, I don’t have bb, just go to the picture 

 Hey, this is fine, but someone must say that it is not convenient to write this line every time you write code, it is worse than _s. nonono, you are wrong to think so, will I only talk about such a complicated method? Then comes the real hard work.

First of all, you need to find such a file called newc++file.cpp in your vs folder, then open it with vs, write the above code in vs, save and close it, and then whenever you open vs , When creating a new project, this line of code will automatically appear on the first line, which effectively solves our problems once and for all. 

 Just like this first (here is a software called everything in Amway, the search function is very powerful, the speed is fast, here is the official website link)

Download - voidtools

Next, let's talk about the problems encountered in the modification process.

Problem and Solution: Cannot Change File Contents

The first point: You can try to open the file as an administrator. The administrator has relatively high permissions and may have the right to change

Second point: If it still doesn’t work, let’s copy the file to the desktop (the reason for copying to the desktop here is also a permission issue, and the desktop has higher permissions), open it on the desktop and write this line of code to save and exit, then overwrite the file. That's it.

The third point: After completing the above operations, the third solution is completed, you can open the vs to see if there is this line of code. (like this)

PS: This is the first time I write a blog, please like and comment to support me, thank you all.

Guess you like

Origin blog.csdn.net/2303_77414881/article/details/131147850