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 ).