高手,帮忙看看这个错在哪里?该怎么处理
高手,帮忙看看这个错在哪里?
我有个程序:
#include "stdio.h"
#include "string.h"
void main()
{
char a[20]="12345";
char b[10]="67890";
strcat(a,b);
printf("%s\n",a);
}
错误如下:
1>------ 已启动全部重新生成: 项目: test, 配置: Debug Win32 ------
1> test.cpp
1>c:\programe\c file functions\test\test\test.cpp(9): warning C4996: 'strcat': This function or variable may be unsafe. Consider using strcat_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
1> c:\program files\microsoft visual studio 10.0\vc\include\string.h(110) : 参见“strcat”的声明
1> test.vcxproj -> C:\programe\c file functions\test\Debug\test.exe
========== 全部重新生成: 成功 1 个,失败 0 个,跳过 0 个 ==========
------解决方案--------------------
不是成功了吗
------解决方案--------------------
用来写测试程序没问题,这是个使用strcat函数的安全警告。
你调用函数的时候没有指定长度,因为字符串都是以\0结尾的,如果你没有\0又没有指定长度的话,有可能会造成内存溢出,数组越界等致命错误
对于这些问题,VC2005以上的版本建议使用这些函数的更高级的安全版本,即在这些函数名后面加了一个_s的函数。这些安全版本函数使用起来更有效,也便于识别,如:strcpy_s,calloc_s等。
------解决方案--------------------
这段程序没什么问题,列出的是警告,不是错误.
要去掉的话用strcat_s代替strcat
------解决方案--------------------
警告而已
------解决方案--------------------
没错误。
------解决方案--------------------
对 安全性 的 warning
我有个程序:
#include "stdio.h"
#include "string.h"
void main()
{
char a[20]="12345";
char b[10]="67890";
strcat(a,b);
printf("%s\n",a);
}
错误如下:
1>------ 已启动全部重新生成: 项目: test, 配置: Debug Win32 ------
1> test.cpp
1>c:\programe\c file functions\test\test\test.cpp(9): warning C4996: 'strcat': This function or variable may be unsafe. Consider using strcat_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
1> c:\program files\microsoft visual studio 10.0\vc\include\string.h(110) : 参见“strcat”的声明
1> test.vcxproj -> C:\programe\c file functions\test\Debug\test.exe
========== 全部重新生成: 成功 1 个,失败 0 个,跳过 0 个 ==========
------解决方案--------------------
不是成功了吗
------解决方案--------------------
用来写测试程序没问题,这是个使用strcat函数的安全警告。
你调用函数的时候没有指定长度,因为字符串都是以\0结尾的,如果你没有\0又没有指定长度的话,有可能会造成内存溢出,数组越界等致命错误
对于这些问题,VC2005以上的版本建议使用这些函数的更高级的安全版本,即在这些函数名后面加了一个_s的函数。这些安全版本函数使用起来更有效,也便于识别,如:strcpy_s,calloc_s等。
------解决方案--------------------
这段程序没什么问题,列出的是警告,不是错误.
要去掉的话用strcat_s代替strcat
------解决方案--------------------
警告而已
------解决方案--------------------
没错误。
------解决方案--------------------
对 安全性 的 warning