问题error C4996: 'scanf': This function or variable may be unsafe. Consider using scanf_s instead. 的解决
来源:互联网 发布:中文翻译拼音软件下载 编辑:程序博客网 时间:2024/05/25 16:39
运行c语言代码是会经常遇见下面的问题:
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.
1> d:\program files\microsoft visual studio 11.0\vc\include\stdio.h(290) : 参见“scanf”的声明
1>C:\Program Files\MSBuild\Microsoft.Cpp\v4.0\V110\Microsoft.CppCommon.targets(347,5): error MSB6006: “CL.exe”已退出,代码为 2。
这种微软的警告,主要因为那些C库的函数,很多函数内部是不进行参数检测的(包括越界类的),微软担心使用这些会造成内存异常,所以就改写了同样功能的函数,改写了的函数进行了参数的检测,使用这些新的函数会更安全和便捷。关于这些改写的函数你不用专门去记忆,因为编译器对于每个函数在给出警告时,都会告诉你相应的安全函数,查看警告信息就可以获知,在使用时也再查看一下MSDN详细了解。
解决方法如下:
一:将原来的旧函数替换成新的安全函数,比如scanf_s函数
二:更改预处理定义:
项目->属性->配置属性->C/C++ -> 预处理器 -> 预处理器定义,增加:_CRT_SECURE_NO_DEPRECATE
三:在预编译头文件 stdafx.h 里(要在没有include任何头文件之前)定义下面的宏:
#define _CRT_SECURE_NO_DEPRECATE
#define _CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES 1
第三种方法来源于网络,没有亲自试验
- 问题error C4996: 'scanf': This function or variable may be unsafe. Consider using scanf_s instead. 的解决
- error C4996: 'scanf': This function or variable may be unsafe. Consider using scanf_s instead. To di
- error C4996: 'scanf': This function or variable may be unsafe. Consider using scanf_s instead.
- 错误1error C4996: 'scanf': This function or variable may be unsafe. Consider using scanf_s instead.
- VS2015:error C4996: 'scanf': This function or variable may be unsafe. Consider using scanf_s instead
- warning C4996: 'scanf': This function or variable may be unsafe. Consider using scanf_s instead. To
- 警告 1 warning C4996: 'scanf': This function or variable may be unsafe. Consider using scanf_s instead
- 已解决error C4996: 'fopen': This function or variable may be unsafe. Consider using fopen_s instead.
- 问题error C4996: 'asctime': This function or variable may be unsafe. Consider using asctime_s instead
- 'scanf': This function or variable may be unsafe. Consider using scanf_s instead.
- 错误1error C4996: 'fopen': This function or variable may be unsafe. Consider using fopen_s instead.
- error C4996: 'sprintf': This function or variable may be unsafe. Consider using sprintf_s instead. T
- error C4996: 'sprintf': This function or variable may be unsafe.Consider using sprintf_s instead.
- error C4996: 'fopen': This function or variable may be unsafe. Consider using fopen_s instead解决方案
- error C4996: 'fopen': This function or variable may be unsafe. Consider using fopen_s instead.
- error C4996: 'sprintf': This function or variable may be unsafe.Consider using sprintf_s instead.
- error C4996: 'strcpy': This function or variable may be unsafe. Consider using strcpy_s instead.
- error C4996: 'sprintf': This function or variable may be unsafe.Consider using sprintf_s instead.
- 【dd】转换并复制文件
- 大神们的博客
- ListView上拉加载更多数据
- 杭电ACM1003
- js字符串常用方法
- 问题error C4996: 'scanf': This function or variable may be unsafe. Consider using scanf_s instead. 的解决
- Android-ClockView
- git常用命令汇总
- iOS URLEcode,URLDecode
- freemarker+spring中文乱码的解决
- 【df】显示磁盘分区使用情况
- Tyvj_P1002
- 树状数组&二维树状数组模板
- 【dumpe2fs】显示文件系统属性信息(更加详细)