解决VS2015中出现类似于error C4996: 'scanf': This function or variable may be unsafe的安全检查错误
用习惯了VS老版本的人当刚使用VS2013的时候可能总遇到类似于这样的错误:
error C4996: 'scanf': This function or variable may be unsafe. Consider using scanf_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
原因是Visual C++ 2015 使用了更加安全的 run-time library routines 。新的Security CRT functions(就是那些带有“_s”后缀的函数)
这个问题一般使用以下几种解决办法:
(1)scanf等类似的函数已经不太安全,要想保证程序的安全性,建议以后采用_s结尾的安全版本,但是很多以前的程序可能还是使用不安全的版本,那么下面给出去掉这种错误提示的几种办法。
(2)在VS中新建项目的时候去掉“安全开发生命周期(SDL)检查”即可将错误转变成警告,使得使用不安全版本也不影响编译和运行,如下图所示。
(3)在头文件包含的最前面,记住是最前面(在include的前面)加上:#define _CRT_SECURE_NO_WARNINGS这个宏定义即可,如下图所示。
(4)在编译的头文件最前面加上:#pragma warning( disable : 4996)即可,类似于上图,此处不再附图。
(5)通过以下步骤Project properties->Configuration Properties->C/C++->Preprocessor->Preprocessor Definitions进入到预处理的定义中,点击按钮 (...),输入:_CRT_SECURE_NO_WARNINGS,使用 "\n" 相隔即可。
总之,如果想完全不做安全检查,就使用(2)中的方法或者(5)中的方法,如果只是对某些文件不使用,可以使用(3)和(4)中的方法,个人喜欢使用(2)中的方法,大家可以根据按需选择,不过随着安全性的重要程度在逐步提高,还是建议大家以后使用安全版本。
解决VS2015中出现类似于error C4996: 'scanf': This function or variable may be unsafe的安全检查错误的更多相关文章
- vs2013/2015中scanf函数类似于error C4996: 'scanf': This function or variable may be unsafe的安全检查错误
在使用vs2015时,遇到了scnaf函数安全性的问题,程序不能正常运行,错误如下: error C4996: 'scanf': This function or variable may be un ...
- 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 ...
- [转]Visual Studio 2012 编译错误【error C4996: 'scanf': This function or variable may be unsafe. 】的解决方案
原文地址:http://www.cnblogs.com/gb2013/archive/2013/03/05/SecurityEnhancementsInTheCRT.html 在VS 2012 中编译 ...
- 错误 1 error C4996: 'scanf': This function or variable may be unsafe. Consider using scanf_s instead
错误简介 在VS 2012 中编译 C 语言项目,如果使用了 scanf 函数,编译时便会提示如下错误: 原因是Visual C++ 2012 使用了更加安全的 run-time library ro ...
- 错误 1 error C4996: 'scanf': This function or variable may be unsafe. Consider using scanf_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details. d:\users\vs2013\le
#define _CRT_SECURE_NO_WARNINGS#include<stdio.h>#include<stdlib.h>void main(){ int nu ...
- error C4996: 'scanf': This function or variable may be unsafe.
项目属性-配置属性-c/c++-预处理器- 在下面的编辑窗口中添加一句命令:_CRT_SECURE_NO_WARNINGS 添加完成后应用并退出 http://jingyan.baidu.com/al ...
- Visual Studio 2012 编译错误【error C4996: 'scanf': This function or variable may be unsafe. 】的解决方案(转载)
转载:http://www.th7.cn/Program/c/201303/127343.shtml 原因是Visual C++ 2012 使用了更加安全的 run-time library rout ...
- 配置OpenCV产生flann\logger.h(66): error C4996: 'fopen': This function or variable may be unsafe问题[zz]
使用vs2012/2013配置opencv编译出现问题: 1>------ 已启动生成: 项目: Win32ForOpenCV245, 配置: Debug Win32 ------ 1> ...
随机推荐
- spring MVC学习(一)---前端控制器
1.spring MVC中的前段控制器就是DsipatcherServlet,它在spring MVC框架中的结构图如下: 2.DispatcherServlet其实就是一个Servlet,它继承了H ...
- gbdt调参的小结
关键部分转自http://www.cnblogs.com/pinard/p/6143927.html 第一次知道网格搜索这个方法,不知道在工业中是不是用这种方式 1.首先从步长和迭代次数入手,选择一个 ...
- 随机深林和GBDT
随机森林(Random Forest): 随机森林是一个最近比较火的算法,它有很多的优点: 在数据集上表现良好 在当前的很多数据集上,相对其他算法有着很大的优势 它能够处理很高维度(feature很多 ...
- 数据库连接池libzdb
官网:http://www.tildeslash.com/libzdb/ A small, easy to use Open Source Database Connection Pool Libra ...
- gcc __attribute__
GNU C 的一大特色就是__attribute__ 机制.__attribute__ 可以设置函数属性(Function Attribute ).变量属性(Variable Attribute )和 ...
- iOS开发debug集锦
1.添加第三方库时,需要注意使用环境 duplicate symbol _llvm.embedded.module in: /Users/dengw/360Cloud/xcode_code/appli ...
- Django Restful API Class Based View
基于class定义view 前言: 我们首先通过以class的方式重写view,我们可以自己构造类也可以通过res_framework 提供的mixins和generics类库直接构造类 下面来看下自 ...
- openJudge C17K:Lying Island
地址:http://poj.openjudge.cn/practice/C17K/ 题目: C17K:Lying Island 查看 提交 统计 提问 总时间限制: 2000ms 内存限制: 26 ...
- spark 作业提交
kafka-topics.sh --describe --zookeeper xxxxx:2181 --topic testkafka-run-class.sh kafka.tools.GetOffs ...
- $Python技巧大全
知乎上有一个问题:Python 有什么奇技淫巧?其中有各种不按套路出牌的招数,也不乏一些惊为天人的"奇技淫巧",会让你大呼:居然还有这种操作??? 本文就是对日常使用过的或者觉得很 ...