warning C4996: 'fopen': This function or variable may be unsafe.(_CRT_SECURE_NO_WARNINGS)

在 windows 平台下的 visual studio IDE,使用 fopen 等 CRT 函数(C runtime library(part of the C standard library)),就会出现一些警告信息,如下:

warning C4996: ‘fopen’: This function or variable may be unsafe. Consider using fopen_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.

解决方法有两种:

  • 法1:右击工程 - 属性 - 配置属性 - C/C++ - 命令行,命令行增加 /D _CRT_SECURE_NO_WARNINGS

  • 法2:自己在头文件中定义

    
    #define _CRT_SECURE_NO_WARNINGS
    
原文地址:https://www.cnblogs.com/mtcnn/p/9423729.html