Warning c4996: "fopen" declared as rejected

Source: Internet
Author: User

From: http://apps.hi.baidu.com/share/detail/24671384

Problem: when programming in vs2005, the following problems are encountered:WarningC4996:"Fopen" is declared as rejected

Warning c4996: 'fopen': This function or variable may be unsafe

    Explanation: Microsoft's warning mainly refers to functions in the C library. Many functions do not provide parameters internally.

 

Detection (including out-of-bounds), Microsoft worried that using this would cause memory exceptions, so it changed

 

The function with the same function is only used for parameter detection. You can use these new functions. No feature

 

Note: Every function will tell you the corresponding security function when giving a warning.

 

Yes, it will be used againCheck out msdn. Example of database function Rewriting:

    Modify mkdir_ Mkdir

     Fopen is rewrittenFopen_s

     Rewrite stricmpStricmp_s

 

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

        Message: "ThisFunctionOrVariableMayBeUnsafe.ConsiderUsing

 

Fopen_sInstead.ToDisableDeprecation,Use_ Crt_secure_no_deprecate.

 

SeeOnlineHelpForDetails ."

        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>Follow the prompts in the following three sentences: 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 lowers according to your situation

 

Warning Level (this method is not recommended)

 

    Note: Warning is highly valued: the highest warning level of the compiler. Should require clean Construction

 

(No warning ). Understand all warnings. PassModify the code instead of lowering the warning level to exclude warnings.

 

.

    The compiler is your friend. If it sends a warning to a constructor, it often indicates that

 

There are potential problems. 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.