Error C4996: 'fopen': This function or variable may be unsafe. in VS2015.

本文描述了在使用OpenCV 3.2.0rc版本时遇到的fopen函数安全性警告,特别是在Windows 10 64位系统下使用Visual Studio 2015 Update 3编译时。提供了详细的错误信息及源代码位置,并展示了如何通过使用fopen_s替代fopen来解决此问题,以避免潜在的安全风险。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

System information (version)

  • OpenCV => 3.2.0 rc (Latest version)
  • Operating System / Platform => Windows10 64bit
  • Compiler => Visual Studio 2015 Update3

Detailed description

Source: %OPENCV_PATH%\include\opencv2\flann\logger.h 67
Error 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.

Steps to reproduce

Build below code with opencv_flann.

#include <Windows.h>
#include <opencv2/opencv.hpp>

void main(int argc, char* argv[])
{
}

int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPSTR lpCmd, int nCmd)
{
    main(0,NULL);
}

logger.h : Original code.

stream = fopen(name,"w");
if (stream == NULL) {
    stream = stdout;
}

logger.h : Fixed code.

 #if _MSC_VER >= 1500
     errno_t error;
     error = fopen_s(&stream, name, "w");
     if (error != 0) {
         stream = stdout;
     }
 #else
     stream = fopen(name,"w");
     if (stream == NULL) {
         stream = stdout;
     }
 #endif

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值