可以使用的最简单的方法:

选项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 方法的更多相关文章

  1. 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 ...

  2. vs的【warning C4996:'fopen': This function or variable may be unsafe】解决方案

    编译警告:warning C4996 与 Security Enhancements in the CRT 将过去的工程用VS2005打开的时候.你有可能会遇到一大堆的警告:warning C4996 ...

  3. 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) ...

  4. “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 ...

  5. 配置OpenCV产生flann\logger.h(66): error C4996: 'fopen': This function or variable may be unsafe问题[zz]

    使用vs2012/2013配置opencv编译出现问题: 1>------ 已启动生成: 项目: Win32ForOpenCV245, 配置: Debug Win32 ------ 1> ...

  6. 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 ...

  7. VS 编译错误【error C4996: 'scanf': This function or variable may be unsafe. 】的解决方案

    在VS中编译 C 语言项目,如果使用了 scanf 函数,编译时便会提示如下错误: error C4996: 'scanf': This function or variable may be uns ...

  8. 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 ...

  9. 解决VS2015中出现类似于error C4996: 'scanf': This function or variable may be unsafe的安全检查错误

    用习惯了VS老版本的人当刚使用VS2013的时候可能总遇到类似于这样的错误: error C4996: 'scanf': This function or variable may be unsafe ...

随机推荐

  1. [置顶] Asp.Net底层原理(二、写自己的Asp.Net框架)

    我们介绍过了浏览器和服务器之间的交互过程,接下来介绍Asp.net处理动态请求. 写自己的Asp.Net框架,我们不会引用System.Web这个程序集,我们只需要创建要给自己的类库,所以在接下来的程 ...

  2. 查找jar包的站点

    1.findJAR.com: http://www.findjar.com/index.x 2.jarfire:  https://cn.jarfire.org/

  3. FZU Problem 2169 shadow

    http://acm.fzu.edu.cn/problem.php?pid=2169 题目大意: S王国有N个城市,有N-1条道路.王都为编号1的城市.叛军驻扎在很多城市.除了王都外有K个城市有军队, ...

  4. MVC3 验证码

    public ActionResult GetValidateCode()        {                         string code = CreateValidateC ...

  5. [译]Stairway to Integration Services Level 13 - SSIS 变量回顾

    介绍 在前一篇中我们组合了已经学过的事件冒泡 event bubbling, 日志记录 logging, 和父子模型 Parent-Child pattern 建立了自定义的SSIS包日志记录. 本文 ...

  6. 两种MD5最后的值不一样,因为两种做法不一样

    //MD5加密 private static string Md5Hash(string input)         {             MD5CryptoServiceProvider m ...

  7. js 模板引擎 jade使用语法

    Jade是一款高性能简洁易懂的模板引擎,Jade是Haml的Javascript实现,在服务端(NodeJS)及客户端均有支持. 功能 · 客户端支持 · 超强的可读性 · 灵活易用的缩进 · 块扩展 ...

  8. windows cmd: 打开windows系统程序或服务的常见命令

    Windows常用CMD命令 http://www.cnblogs.com/sbaicl/archive/2013/03/05/2944001.html 其实查找Windows自带程序的命令行很简单, ...

  9. linux基本命令-注销、关机、重起

    链接地址:http://blog.163.com/bhao_home/blog/static/6647763120081202047945/ 一.注销,关机,重启 注销系统的logout命令 1,Lo ...

  10. poj2774之最长公共子串

    Long Long Message Time Limit: 4000MS   Memory Limit: 131072K Total Submissions: 18794   Accepted: 77 ...