vc2015关于_CRT_SECURE_NO_WARNINGS的bug

首先,我的代码如下:

#include "stdafx.h"


#include <cassert>
#include <string>
#include <boost/iostreams/filtering_stream.hpp>
#include <boost/range/iterator_range.hpp>
#include <boost/iostreams/tee.hpp>
#include <boost/iostreams/compose.hpp>
#include <boost/iostreams/filter/regex.hpp>
#include <boost/iostreams/filter/grep.hpp>
#include <boost//iostreams/copy.hpp>
#include <boost/iostreams/device/back_inserter.hpp>


namespace io = boost::iostreams;
int main(){
using namespace std;
  string str("abcdef aochijk");
  string result;
io::copy(
boost::make_iterator_range(str),
tee(
compose(io::regex_filter(boost::regex("a.c"),"test"),cout),
io::back_inserter(result)
)
);
    return 0;

}

编译后,引发如下错误:

------ 已启动生成: 项目: testStream, 配置: Debug Win32 ------
1>  testStream.cpp
1>c:\program files (x86)\microsoft visual studio 14.0\vc\include\xutility(2372): error C4996: 'std::copy::_Unchecked_iterators::_Deprecate': Call to 'std::copy' 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'

......(未贴出完整错误)

PS:多次测试为boost::make_iterator_range(str)引发的xutility(2372): error C4996错误。

    以网上查后,提出在“项目->属性->配置属性->C/C++->预处理器->预处理器定义”(末尾加上“_SCL_SECURE_NO_WARNINGS”即可(注意分号隔开)解决方案,但编译后还是出现上述错误,

如果再在文件“stdafx.h”中增加:#define _ITERATOR_DEBUG_LEVEL 0

      后编译则会引发如下错误:

1>------ 已启动全部重新生成: 项目: testStream, 配置: Debug Win32 ------
1>  stdafx.cpp
1>  testStream.cpp
1>libboost_regex-vc140-mt-gd-1_64.lib(regex_traits_defaults.obj) : error LNK2038: 检测到“_ITERATOR_DEBUG_LEVEL”的不匹配项: 值“2”不匹配值“0”(testStream.obj 中)
1>libboost_regex-vc140-mt-gd-1_64.lib(instances.obj) : error LNK2038: 检测到“_ITERATOR_DEBUG_LEVEL”的不匹配项: 值“2”不匹配值“0”(testStream.obj 中)
1>libboost_regex-vc140-mt-gd-1_64.lib(regex.obj) : error LNK2038: 检测到“_ITERATOR_DEBUG_LEVEL”的不匹配项: 值“2”不匹配值“0”(testStream.obj 中)
1>libboost_regex-vc140-mt-gd-1_64.lib(static_mutex.obj) : error LNK2038: 检测到“_ITERATOR_DEBUG_LEVEL”的不匹配项: 值“2”不匹配值“0”(testStream.obj 中)
1>libboost_regex-vc140-mt-gd-1_64.lib(w32_regex_traits.obj) : error LNK2038: 检测到“_ITERATOR_DEBUG_LEVEL”的不匹配项: 值“2”不匹配值“0”(testStream.obj 中)
1>libboost_regex-vc140-mt-gd-1_64.lib(regex_raw_buffer.obj) : error LNK2038: 检测到“_ITERATOR_DEBUG_LEVEL”的不匹配项: 值“2”不匹配值“0”(testStream.obj 中)

1>F:\MyCode\testStream\testStream\Debug\testStream.exe : fatal error LNK1319: 检测到 6 个不匹配项

    通过修改代码发现如果代码中去除boost::regex()类,则不会出error LNK2038错误,所以在不使用boost::regex()类的情况下boost::make_iterator_range(str)引发的xutility(2372): error C4996错误的初步解决方案为”项目->属性->配置属性->C/C++->预处理器->预处理器定义”(末尾加上“_SCL_SECURE_NO_WARNINGS”,及在文件“stdafx.h”中增加:#define _ITERATOR_DEBUG_LEVEL 0。

    后来我再试在文件“stdafx.h”中增加:#define _SCL_SECURE_NO_WARNINGS一行发现在文件“stdafx.h”中不需要#define _ITERATOR_DEBUG_LEVEL 0一行也能通过测试。

   那么问题来了:为何在项目->属性->配置属性->C/C++->预处理器->预处理器定义”与“stdafx.h”文件中定义_SCL_SECURE_NO_WARNINGS会有不同的结果呢。这是vc2015的一个bug吗?


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值