关于VS2003中的Warning:strcpy was declared deprecated.
来源:互联网 发布:可牛闪图软件下载 编辑:程序博客网 时间:2024/05/18 22:09
VC2005/2003中认为CRT中的一组函数如果使用不当,可能会产生诸如内存泄露、缓冲区溢出、非法访问等安全问题。这些函数如:strcpy、strcat等。 对于这些问题,VC2005建议使用这些函数的更高级的安全版本,即在这些函数名后面加了一个_s的函数。这些安全版本函数使用起来更有效,也便于识别,如:strcpy_s,calloc_s等。
在网上搜索到的最常用的解决方案,那就是定义 _CRT_SECURE_NO_DEPRECATE 和_SCL_SECURE_NO_DEPRECATE 来禁止vc2005对此产生警告(依然使用的是非安全库!0显然并不是一个好的解决方案)。而且如果使用了ATL,则还需要定义 _ATL_SECURE_NO_DEPRECATE, 使用了MFC则需要定义 _AFX_SECURE_NO_DEPRECATE。
然而尽管如此,更好的解决方案只需要定义一个宏 _CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES, 那么vc将会自动替换使用他们的Safe Library来代替C/C++标准库(如strcat将被strcat_f来取代)。
解决的方法是:在VS2005的Project菜单栏下:找到编译选项(Properties): C/C++ | Preprocessor |Preprocessor Definitions中,增加_CRT_SECURE_NO_DEPRECATE标记即可.
但fopen仍然需要自己改成:fopen_s。由于二者包含的参数是不同的,要用不同的形式:
如果用fopen:
FILE *fp;
fp = fopen(filename,"r");
if(fp == NULL)
{
printf("can't find this file!/n");
exit(0);
}
如果用fopen_s:
FILE *fp;
if((fopen_s(&fp,filename,"r")) != 0)
{
printf("can't find this file!/n");
exit(0);
}
- 关于VS2003中的Warning:strcpy was declared deprecated.
- warning C4996: strcpy was declared deprecated
- warning C4996: ''strcpy'' was declared deprecated
- warning C4996: 'strcpy' was declared deprecated
- VS2005 出现warning C4996: strcpy was declared deprecated
- visual studio 2005:warning C4996: strcpy was declared deprecated
- VS2005 出现warning C4996: strcpy was declared deprecated
- VS2005编译VC6的工程,warning C4996: strcpy was declared deprecated
- (转)出现这样的警告 warning C4996: strcpy was declared deprecated
- VS2005 出现警告warning C4996: strcpy was declared deprecated 的解决办法
- VC2005去掉烦人的warning C4996: '×××' was declared deprecated
- warning C4996: 'sprintf' was declared deprecated see declaration of 'sprintf'
- warning C4996: 'sprintf' was declared deprecated see declaration of 'sprintf'
- 《warning C4996: 'sprintf' was declared deprecated see declaration of 'sprintf'》
- Visual C++ Tips: warning C4996: 'stricmp' was declared deprecated
- vc2005 : declared deprecated warning
- 'function': was declared deprecated
- 'scanf' was declared deprecated,
- DataSet,DataTable 不使用EXCEL组件直接保存为EXCEL
- 【已解决】Adobe CS3遇到问题需要关闭……
- 类型转换
- urllib2 对 redirect / cookie 的处理方法
- 设计模式笔记(五) —— 代理模式
- 关于VS2003中的Warning:strcpy was declared deprecated.
- 十句话
- ccna言论
- LINUX下完全卸载ORACLE 10G的方法
- 如何理解c和c++ 的复杂类型声明
- javascript substr() 和 substring()区别
- [转]由浅到深详细讲解JSP自定义标签
- 设计模式笔记(六) —— 工厂方法模式
- 虚拟主机上用Asp.net实现Urlrewrite