编译 errorC4996错误 -D_SCL_SECURE_NO_WARNINGS

来源:互联网 发布:sql server 求和 编辑:程序博客网 时间:2024/06/02 06:20

今天项目中使用protocol buffer生成的一个c++文件是时遇到一个编译问题,查看输出窗口后发现是google protocolbuf库中用的std::copy()函数导致的

在vs 2012中进行编译会弹出如下信息:

error C4996: 'std::_Copy_impl': Function call with parameters that may be unsafe - this call relies on the caller to check that the passed values are correct. To disable this warning, use -D_SCL_SECURE_NO_WARNINGS. See documentation on how to use Visual C++ 'Checked Iterators'

而在vs 2010中却仍可以正确编译并运行,所显示的编译信息如下:

warning C4996: 'std::_Copy_impl': Function call with parameters that may be unsafe - this call relies on the caller to check that the passed values are correct. To disable this warning, use -D_SCL_SECURE_NO_WARNINGS. See documentation on how to use Visual C++ 'Checked Iterators'

原因是在vs 2012中提升了安全机制,在这里如果我们还是想直接使用这两个函数那么,我们可以在使用前添加如下的宏定义:

ifndef_SECURE_SCL

#define_SECURE_SCL 0 

#else

#undef_SECURE_SCL 

#endif

或者直接关闭警告:

pragma warning(disable:4996)

0 0
原创粉丝点击