Fopen warning Handling Method

Source: Internet
Author: User

Warning c4996: "fopen" declared as rejected

Problem: when programming in vs2005, the following problems are encountered:

Warning c4996: "fopen" is declared as rejected.

Explanation: Microsoft's warning mainly refers to functions in the C library. Many functions do not perform parameter detection (including out-of-bounds functions). Microsoft is worried that using these functions will cause memory exceptions, so I changed a function with the same function, but I checked the parameters and used these new functions. You don't need to remember it. Every function will tell you the corresponding security function when giving a warning. Pay attention to the warning information and check msdn again when using it. Example of database function Rewriting:

Modify mkdir to _ mkdir.

Fopen is rewritten to fopen_s

Rewrite stricmp to stricmp_s

Solution:

1> follow the following warning prompt: see the "fopen" statement.

Message: "This function or variable may be unsafe. Consider using fopen_s instead. To disable deprecation, use _ crt_secure_no_deprecate. See online help for details ."

Therefore, you can use the fopen_s function in the second sentence prompted by warning:

Eg: file * pfile = fopen ("1.txt"," W ");

Changed:

File * pfile;

Fopen_s (& pfile, "1.txt"," W ");

2> Use _ crt_secure_no_deprecate

Project | attribute | Configuration Attribute | C/C ++ | Command Line | add [/d

"_ Crt_secure_no_deprecate"] (Note: add the complete content in brackets)

3> lower warning level: Project | attribute | Configuration Attribute | C/C ++ | standard, which can be lowered as needed

Warning Level (this method is not recommended)

Note: Warning is highly valued: the highest warning level of the compiler. The build should be clean (no warning ). Understand all warnings. You can exclude warnings by modifying the code rather than lowering the warning level.

The compiler is your friend. If it sends a warning to a constructor, it often indicates a potential problem in your code. Successful building should be silent (with no warning ).

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.