error C4996: 'std::_Copy_impl'
以下代码段在VS2008编译可以通过,只是会提示不安全;
std::vector<unsigned char> fileData ="asdfsfsfsfsdf";//随便打的
//文件数据大小
int size = fileData.size();
//字节数组
char* data = new char[size + 1];
//把二进制数据复制到数组
std::copy(fileData.begin(), fileData.end(), data);
data[size] = 0;
但在VS2012就不能编译通过,VS2012进行了强制类型检查
1>C:\Program Files\Microsoft Visual Studio 11.0\VC\include\xutility(2176): 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'
1> C:\Program Files\Microsoft Visual Studio 11.0\VC\include\xutility(2157) : 参见“std::_Copy_impl”的声明
1> HashParser.cpp(43): 参见对正在编译的函数 模板 实例化“_OutIt std::copy<std::_Vector_iterator<_Myvec>,char*>(_InIt,_InIt,_OutIt)”的引用
1> with
1> [
1> _OutIt=char *,
1> _Myvec=std::_Vector_val<std::_Simple_types<unsigned char>>,
1> _InIt=std::_Vector_iterator<std::_Vector_val<std::_Simple_types<unsigned char>>>
1> ]
解决:修改代码如下
std::vector<unsigned char> fileData = "sdfasdfasdfasf";
//文件数据大小
int size = fileData.size();
//字节数组
char* data = new char[size + 1];
//把二进制数据复制到数组
std::copy(fileData.begin(), fileData.end(), stdext::unchecked_array_iterator<char*>(data));
data[size] = 0;
参考:
http://choorucode.com/2010/08/30/visual-c-c4996-warning-on-copy-with-array-parameters/
error C4996: 'std::_Copy_impl'的更多相关文章
- VS2013编译程序出现error C4996: 'std::_Fill_n': Function call with parameters that may be unsafe
最近按照BiliBil网站Visual C++网络项目实战视频教程,使用VS2013编写一个基于MFC的对话框程序HttpSourceViewer,采用了WinHttp库.Boost xpressiv ...
- windows下编译caffe出现错误 C4996: 'std::_Copy_impl': Function call with parameters that may be unsafe?
解决方案来自http://blog.csdn.net/u012556077/article/details/50353818
- error C4996: Function call with parameters that may be unsafe – this call relies on the caller to ch
在加入QCustomplot时有如题的错误 1>c:\program files (x86)\microsoft visual studio11.0\vc\include\xutility(21 ...
- C++解决error C4996报错
今天用c++写了个数独程序,在编译过程中报了一个错误: 1>------ 已启动生成: 项目: sudoku, 配置: Debug Win32 ------1> main.cpp1> ...
- vs2012 error c4996: This function or variable may be unsafe
编译lua源码时,使用vs2012,遇到如下错误. 1>------ 已启动生成: 项目: 20130925, 配置: Debug Win32 ------ 1> stdafx.cpp ...
- 配置OpenCV产生flann\logger.h(66): error C4996: 'fopen': This function or variable may be unsafe问题[zz]
使用vs2012/2013配置opencv编译出现问题: 1>------ 已启动生成: 项目: Win32ForOpenCV245, 配置: Debug Win32 ------ 1> ...
- 1 error C4996: 'pcl::SAC_SAMPLE_SIZE':
使用PCL1.8 中使用粗配准拼接 错误 1 error C4996: 'pcl::SAC_SAMPLE_SIZE': This map is deprecated and is kept onl ...
- error C4996: 'fopen': This function or variable may be unsafe.
vs2013中错误提示信息: error C4996: 'fopen': This function or variable may be unsafe. Consider using fopen_s ...
- VS2013-解决error C4996: 'fopen'问题
VS2013中如何解决error C4996: 'fopen'问题 初次使用vs系列编辑器编写控制台应用程序时常出现如下错误: error C4996: 'fopen': This function ...
随机推荐
- Realtime Data Processing at Facebook
概要 这篇论文发表于2016年,主要是介绍Facebook内部的流式计算平台的设计与思考,对于流式计算的关键特性的实现选型上进行深度对比分析. 流式计算系统5个衡量指标 文中提到有5个重要的考量部分 ...
- springBoot-启动原理
注:SpringBoot版本 2.6.2 SpringBoot的入口是从SpringApplication.run()传入我们的主启动类开始 @SpringBootApplication public ...
- IDEA 端口占用,启动失败,提示Web server failed to start. Port 8080 was already in use.
问题描述: 使用IDEA开发Spring Boot项目,今天启动提示端口占用,导致启动失败!(我昨天也是用的这个端口,可以正常启动) *************************** APPLI ...
- github push时提示Username for 'https://github.com' 解决办法
问题 github push时在输入账号密码后仍提示:Username for 'https://github.com',需要进一步输入账号密码. 解决方案 注意这里的账号密码并不是github的登录 ...
- 【C# .Net GC】GC的类型与工作方式 和配置
.net主要有两种类型垃圾回收器,也可也说是垃圾回收器的两种工作模式. GC的类型主要有两种: 工作模式是针对进程的,程序启动后就不能修改了.只能在配置文件.json .xml进行设置.但是可用通过G ...
- 【VS 2022】给vs2022 添加类设计图
一.安装 1.开始菜单>找到 visual studio installer,单击打开 2.点击修改 3.在单个组件选项卡找到 类设计图 ,选择后点击安装 二.使用 1.右键要查看的项目-&q ...
- RabbitMQ安装以及简单操作应用(针对Windows和C#)
1.RabbitMQ安装 1.1下载并安装Erlang https://www.erlang.org/downloads 一直点next就安装好了.我直接使用了默认的安装目录.否则的话,应该需要配置一 ...
- 递归Recursion
从开始自学写代码开始,就感觉递归是个特别美丽的算法. "如果使用循环,程序的性能可能更高:如果使用递归,程序可能更容易理解.如何选择要看什么对你来说更重要." 编写递归函数时,必须 ...
- 如何在win server中更改服务器密码长度最小值
转至:https://jingyan.baidu.com/article/3aed632e65c7843111809122.html windows server 2008是一种服务器的操作系统,有较 ...
- ceph 问题总结已解决
waiting for a volume to be created, either by external provisioner "ceph.com/rbd" or manua ...