error C4996: 'sprintf': This function or variable may be unsafe.
Visual Studio 2012诸如此类的问题
- 原因是Visual C++ 2005使用了更加安全的run-time library routines。
- 新的Security CRT functions(就是那些带有“_s”后缀的函数):
- http://msdn2.microsoft.com/en-us/library/wd3wzwts(VS.80).aspx
- 那么如何搞定这些警告呢:
以下为转载
1、将过去的工程用VS2010打开的时候。你有可能会遇到一大堆的警告:warning C4996。
比如:warning C4996: 'sprintf': This function or variable may be unsafe. Consider using sprintf_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS.
原因是Visual C++ 2005使用了更加安全的run-time library routines。
新的Security CRT functions(就是那些带有“_s”后缀的函数):
http://msdn2.microsoft.com/en-us/library/wd3wzwts(VS.80).aspx
那么如何搞定这些警告呢:
原因解释
这种微软的警告,主要因为那些C库的函数,很多函数内部是不进行参数检测的(包括越界类的),微软担心使用这些会造成内存异常,所以就改写了同样功能的函数,改写了的函数进行了参数的检测,使用这些新的函数会更安全和便捷。关于这些改写的函数你不用专门去记忆,因为编译器对于每个函数在给出警告时,都会告诉你相应的安全函数,查看警告信息就可以获知,在使用时也再查看一下MSDN详细了解。库函数改写例子:
mkdir改写为 _mkdir
fopen”改写为 fopen_s
stricmp改写为 stricmp_s
sprintf改写为sprintf_s
strcpy改写为strcpy_s
方法一:调用VS2005鼓吹的那些带“_s”后缀的非标准函数,即在其后加上"_S",如sprintf改为sprintf_s 。
方法二:在文件最开始添加#define _CRT_SECURE_NO_DEPRECATE或#pragma warning(disable:4996) ,这是忽略警告的方法(一般比较少用)。
方法三:干粹在工程属性中设置(推荐)。
在工程属性中设置的方法如下:
对于VC6:
打开Project----settings----Resources----Preprocessor definitions,
添加_CRT_SECURE_NO_DEPRECATE和_SCL_SECURE_NO_DEPRECATE这两个宏。
对于VS系列的版本:
打开项目----项目属性---配置属性----C/C++ ----预处理器----预处理定义,
添加_CRT_SECURE_NO_DEPRECATE和_SCL_SECURE_NO_DEPRECATE这两个宏。
error C4996: 'sprintf': This function or variable may be unsafe.的更多相关文章
- VS2013编译报错error C4996: 'sprintf': This function or variable may be unsafe. Consider using sprintf_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS.
解决方法有两个: 1. 在预编译头文件stdafx.h里(在没有include任何头文件之前)定义下面的宏: #define _CRT_SECURE_NO_DEPRECATE 2. 将sprintf函 ...
- : error C4996: 'sprintf': This function or variable may be unsafe. Consider using sprintf_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
打开项目----项目属性---配置属性----C/C++ ----预处理器----预处理定义,添加_CRT_SECURE_NO_WARNINGS
- 配置OpenCV产生flann\logger.h(66): error C4996: 'fopen': This function or variable may be unsafe问题[zz]
使用vs2012/2013配置opencv编译出现问题: 1>------ 已启动生成: 项目: Win32ForOpenCV245, 配置: Debug Win32 ------ 1> ...
- 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 ...
- error C4996: 'strcpy': This function or variable may be unsafe.
vs2012用strcpy遇到的错误. 错误描述:error C4996: 'strcpy': This function or variable may be unsafe. Consider us ...
- VS 编译错误【error C4996: 'scanf': This function or variable may be unsafe. 】的解决方案
在VS中编译 C 语言项目,如果使用了 scanf 函数,编译时便会提示如下错误: error C4996: 'scanf': This function or variable may be uns ...
- Visual Studio 2012 编译错误【error C4996: 'scanf': This function or variable may be unsafe. 】的解决方案
在VS 2012 中编译 C 语言项目,如果使用了 scanf 函数,编译时便会提示如下错误: error C4996: 'scanf': This function or variable may ...
- vs2012 error c4996: 'fopen': This function or variable may be unsafe
1>------ 已启动生成: 项目: 20130925, 配置: Debug Win32 ------1> stdafx.cpp1>d:\code\20130925\201309 ...
- 解决VS2015中出现类似于error C4996: 'scanf': This function or variable may be unsafe的安全检查错误
用习惯了VS老版本的人当刚使用VS2013的时候可能总遇到类似于这样的错误: error C4996: 'scanf': This function or variable may be unsafe ...
随机推荐
- Android 音视频深入 十三 OpenSL ES 制作音乐播放器,能暂停和调整音量(附源码下载)
项目地址https://github.com/979451341/OpenSLAudio OpenSL ES 是基于NDK也就是c语言的底层开发音频的公开API,通过使用它能够做到标准化, 高性能,低 ...
- 小白的python之路10/22 day1
一.操作系统 操作系统就是一个协调.管理和控制计算机硬件资源和软件资源的控制程序.操作系统所处的位置如下图
- 调用 LoadLibraryEx 失败,在 ISAPI 筛选器 "C:\Program Files\php\php5isapi.dll"
把 ISAPI 筛选器这里的php配置删掉,php改用fastcgi配置
- @SpringBootApplication(exclude = {DataSourceAutoConfiguration.class}) 注解的作用
在学习boot 项目的时候 ,发现在启动类中有一个这个的注解 @SpringBootApplication(exclude = {DataSourceAutoConfiguration.class}) ...
- NSIS脚本 打包安装程序
相关工具 nsis http://nsis.sourceforge.net/Special_Builds HM NIS Edit http://hmne.sourceforge.net/ 例子: ; ...
- CodeForces - 589A (STL容器的使用)
Polycarp has quite recently learned about email aliases. Of course, he used to suspect that the case ...
- BootstrapValidator . select 必须选择一个 .callback . select .option
1.对于: 如果 只是引用 notEmpty , 不起作用. 因为 请选择教师 也是一个 option , 一个选项. 可以使用 callback. 'userId':{ message :'教 ...
- .NET并行计算和并发4-Thread-Relative Static Fields and Data Slots
Thread Local Storage: Thread-Relative Static Fields and Data Slots 文章摘自msdn library官方文档 可以使用托管线程本地存储 ...
- java学习笔记38(sql注入攻击及解决方法)
上一篇我们写了jdbc工具类:JDBCUtils ,在这里我们使用该工具类来连接数据库, 在之前我们使用 Statement接口下的executeQuery(sql)方法来执行搜索语句,但是这个接口并 ...
- HTML和CSS标签常用命名规则
1.Images 存放一些网站常用的图片: 2.Css 存放一些CSS文件: 3.Flash 存放一些Flash文件: 4.PSD 存放一些PSD源文件: 5.Temp 存放所有临时图片和其它文件: ...