删除: warning C4996: 'sprintf': This function or variable may be unsafe. Consider 方法
可以使用的最简单的方法:
选项Project | Configuration Properties | C/C++ | Preprocessor | Preprocessor Definitions
加入_CRT_SECURE_NO_DEPRECATE和_SCL_SECURE_NO_DEPRECATE
以下转自: http://blog.csdn.net/hylaking/archive/2007/07/20/1700475.aspx
一、WINVER
Compile result:
WINVER not defined. Defaulting to 0x0502 (Windows Server 2003)
windows server 2003
winver>=0x0502
windows xp
winver>=0x0501
windows 2000
winver>=0x0500
windows nt 4.0
winver>=0x0400
windows me
winver>=0x0500
windows 98
winver>=0x0410
windows 95
winver>=0x0400
在stdafx.h的开头定义:
0x0501是XP SP2的
#ifndef WINVER
#define WINVER 0x0501
#endif
二、编译警告:warning C4996 与 Security Enhancements in the CRT
将过去的project用VS2005打开的时候。
你有可能会遇到一大堆的警告:warning C4996。
比方:
warning 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.
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
那么怎样搞定这些警告呢:
方法一:将原来的旧函数替换成新的Security CRT functions。
方法二:用下面方法屏蔽这个警告。
1.在预编译头文件stdafx.h里(注意:一定要在没有include不论什么头文件之前)定义以下的宏:
#define _CRT_SECURE_NO_DEPRECATE
2.#param warning(disable:4996)
3.更改预处理定义:
项目->属性->配置属性->C/C++ -> 预处理器 -> 预处理器定义,添加_CRT_SECURE_NO_DEPRECATE
方法三:方法二没有使用新的更安全的CRT函数。显然不是一个值得推荐的方法,但是你又不想一个一个地改,那么另一个更方便的方法:
在预编译头文件stdafx.h里(相同要在没有include不论什么头文件之前)定义以下的宏:
#define _CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES 1
在链接的时候便会自己主动将旧函数替换成Security CRT functions。
注意:这种方法尽管使用了新的函数,可是不能消除警告(原因见红字),你还得同一时候用法二。。。
三、link error 1104
原因:当从vc6移植到.net时。会导致这个链接错误!
解决:项目属性->配置属性->链接器->输入->忽略特定库,增加libcd.lib;或直接在命令行中增加: /nodefaultlib:"libcd.lib"
注意:是否是libcd.lib,与C/C++属性中的“代码生成”选项相关
四/
中文VC8的程序猿可能会经常看见这个warning:
warning C4819: 该文件包括不能在当前代码页(936)中表示的字符。请将该文件保存为 Unicode 格式以防止数据丢失.
这个警告没有什么坏影响。但会影响心情:) 所以还是要治理一下:
哪个文件出现这个警告错误,打开它。 用VS2005的查找替换功能。打开同意正則表達式选项,选择当前窗体,查找替换 /n 为 /n , 然后,这个世界就清净了。
原因: 查找的 /n 是跨平台的回车,替换的 /n 却是当前代码页的回车了。
參考:
Security Enhancements in the CRT :
http://msdn2.microsoft.com/en-us/library/8ef0s5kh(VS.80).aspx
Secure Template Overloads :
http://msdn2.microsoft.com/en-us/library/ms175759(VS.80).aspx
删除: warning C4996: 'sprintf': This function or variable may be unsafe. Consider 方法的更多相关文章
- error C4996: 'sprintf': This function or variable may be unsafe.
error C4996: 'sprintf': This function or variable may be unsafe. error C4996: 'sprintf': This func ...
- vs的【warning C4996:'fopen': This function or variable may be unsafe】解决方案
编译警告:warning C4996 与 Security Enhancements in the CRT 将过去的工程用VS2005打开的时候.你有可能会遇到一大堆的警告:warning C4996 ...
- warning C4996: 'fopen': This function or variable may be unsafe.(_CRT_SECURE_NO_WARNINGS)
在 windows 平台下的 visual studio IDE,使用 fopen 等 CRT 函数(C runtime library(part of the C standard library) ...
- “warning C4996: 'fopen': This function or variable may be unsafe”和“LINK : fatal error LNK1104”的解决办法
程序有时编译出现警告C4996,报错: warning C4996: 'fopen': This function or variable may be unsafe. Consider using ...
- 配置OpenCV产生flann\logger.h(66): error C4996: 'fopen': This function or variable may be unsafe问题[zz]
使用vs2012/2013配置opencv编译出现问题: 1>------ 已启动生成: 项目: Win32ForOpenCV245, 配置: Debug Win32 ------ 1> ...
- Visual Studio 2015 编译错误【错误 C4996 'vsprintf': This function or variable may be unsafe. Consider using vsprintf_s instead. 】的解决方案
错误提示信息: 错误 C4996 'vsprintf': This function or variable may be unsafe. Consider using vsprintf_s inst ...
- 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 ...
- 解决VS2015中出现类似于error C4996: 'scanf': This function or variable may be unsafe的安全检查错误
用习惯了VS老版本的人当刚使用VS2013的时候可能总遇到类似于这样的错误: error C4996: 'scanf': This function or variable may be unsafe ...
随机推荐
- perl5 第七章 控制结构
第七章 控制结构 by flamephoenix 一.条件判断二.循环: 1.while循环 2.until循环 3.for循环 4.针对列表(数组)每个元素的foreach循环 5. ...
- 用nodejs安装hexo,将hexo部署到github
跌跌撞撞写这篇博文,希望下一篇可以好点 运行环境:最新版本的nodejs + git 安装好nodejs 和 git ,注册好github账号,新建仓库****.github.io(****为gith ...
- Cloudera Manager、CDH零基础入门、线路指导 http://www.aboutyun.com/thread-9219-1-1.html (出处: about云开发)
Cloudera Manager.CDH零基础入门.线路指导http://www.aboutyun.com/thread-9219-1-1.html(出处: about云开发) 问题导读:1.什么是c ...
- Linux命令压缩与解压缩
zip格式的文件:zip和unzip zip 命令: # zip test.zip test.txt 它会将 test.txt 文件压缩为 test.zip ,当然也可以指定压缩包的目录,例如 /ro ...
- Single Number i and ii
Single Number Given an array of integers, every element appears twice except for one. Find that sing ...
- MySql 初次安装登陆
名称:随便写 服务器:127.0.0.1或者localhost 端口:在安装mysql应该看到是3306 用户:root 密码:(默认的是空,如果你设置过自己应该知道) 其他就可以不用设置
- Xamarin.Android开发实践(三)
原文:Xamarin.Android开发实践(三) 一.前言 用过Android手机的人一定会发现一种现象,当你把一个应用置于后台后,一段时间之后在打开就会发现应用重新打开了,但是之前的相关的数据却没 ...
- Multiple markers at this line @Override的解决方法
Multiple markers at this line - implements java.awt.event.ActionListener.actionPerformed - The metho ...
- UINavigationController具体解释(二)
@UINavigationBar-----(是一个View)基本介绍 1.导航栏,和导航控制器一样,是一个容器用来显示提供的其它对象的内容 2.导航栏显示的内容,通过设置UINavigationIte ...
- Physiological Processes of Speech Production--Reading Notes (8)
Upper Jaw The upper jaw, or the maxilla with the upper teeth, is the structure fixed to the skull, f ...