删除: 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 ...
随机推荐
- javascript 定义类(转载)
Javascript本身并不支持面向对象,它没有访问控制符,它没有定义类的关键字class,它没有支持继承的extend或冒号,它也没有用来支持虚函数的virtual,不过,Javascript是一门 ...
- makinacorpus/spynner
makinacorpus/spynner Intro Contents Intro Credits Companies Authors Contributors Dependencies Feedba ...
- Candy Sharing Game(模拟搜索)
Candy Sharing Game Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Other ...
- ecshop标签大全 各个页面常用标签大全
先从index.php主页开始 页面关键字 {$keywords } 页面标题 {$page_title} 产品分类 父分类列表 {foreach from=$categories item=cat ...
- Foundation Sorting: Shellsort
/* Shell Sorting. * Implemention history:. * 2013-09-15, Mars Fu, first version. */ /* [Shell Sortin ...
- cocos2d-x学习资源汇总(持续更新。。。)
引用地址:http://www.cnblogs.com/zilongshanren/archive/2012/02/17/2356516.html 我之前一直学习c++的,第一次接触cocos2d是o ...
- js之form表单的获取
js中获取form的方法: 1. 利用表单在文档中的索引或表单的name属性来引用表单 document.forms[i] //得到页面中的第i个表单 document.forms[formName] ...
- CentOS环境下R语言的安装和配置
最近在看数据统计和分析,想到了R语言,于是就着手在自己的CentOS环境下进行安装和配置.步骤如下: 1.前往R官网下载安装包. 2.解压压缩包:tar xvzf R-3.2.2.tar.gz 3.进 ...
- linux shell awk 流程控制语句(if,for,while,do)详细介绍
在linux awk的 while.do-while和for语句中允许使用break,continue语句来控制流程走向,也允许使用exit这样的语句来退出.break中断当前正在执行的循环并跳到循环 ...
- 关于Ubuntu12.04下code::blocks不能使用debug解决方法
问题描述: 系统:ubuntu 12.04 code::blocks版本:10.05 问题现象:debug->start 之后出现:warning: GDB: Fail ...