删除: 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 ...
随机推荐
- HDU 2501 Tiling_easy version
递推式:f[n]=2*f[n-2]+f[n-1] #include <cstdio> #include <iostream> using namespace std; ]; i ...
- 细数C++和C的差别
C++语言是对C语言的扩展.所以熟悉C语言的人会发现.本书的第01~18章讲的内容基本上和C语言的内容差点儿相同. C++一方面对C语言的语法进行了改动.还有一方面又加入一些新的概念. C++中新增的 ...
- rman备份优化思路
本章不讲rman备份原理.仅仅提供一些思路 1.oracle11g 选择压缩算法为中级: 2.添加rman备份的通道. 以上两种做法.添加CPU的利用率,降低IO 3.指定rate參数 这个rate和 ...
- android 中文 api (71) —— BluetoothServerSocket[蓝牙]
前言 本章内容是 android.bluetooth.BluetoothServerSocket,为Android蓝牙部分的章节翻译.服务器通讯套接字,与TCP ServerSocket类似.版本为 ...
- js静态方法和实例方法
js静态方法 function foo(){} // 声明类 foo.method = function(){} // 方法体 使用:foo.method() js实例方法 function foo( ...
- C#直接插入排序
以Int类型数组为举例 namespace 直接插入排序 { class Program { private static void Insert(int[] arrayList) { bool is ...
- Ubuntu 15.04 设置thin1.6.4作为Rails4.2.5的默认服务器
0. gem install thin //安装1.6.4 1. 进入到Raisl项目的根目录. 2. 在Gemfile中加入一行 gem 'thin' 3. 运行 bundle install 4. ...
- Stbdroid之ShapeDrawable
Shape可以定义矩形.椭圆形.线条.圆形 <?xml version="1.0" encoding="utf-8"?> <shape xml ...
- java集群
java集群 分类: java学习2011-05-12 09:12 7531人阅读 评论(9) 收藏 举报 java服务器负载均衡ejb集群数据库 序言 越来越多的关键应用运行在J2EE(Java 2 ...
- [lua]笔试-按字典序列出指指定的序列的位置
计算方法: n的阶乘记为f(n), s为输入序列, sub(i)为s的i到n的子序列.A(i)为第i位对应的字母在子序列sub(i)中的字典顺序 N(s) = sum_{1,n} T(i)*(A(i) ...