strcpy的警告求解决
warning C4996: 'strcpy': This function or variable may be unsafe. Consider using strcpy_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
我用的是vs2088,但是vc6.0不会有这个警告求高手解答!
[解决办法]
定义这个宏就可以了。
#define _CRT_SECURE_NO_WARNINGS
[解决办法]
用这个函数strcpy_s
[解决办法]
编译器决定的事情、、不好问为什么
[解决办法]
不是提示你用strcpy_s,VS2008比VC6更严警
[解决办法]
使用VS2005以上版本(VS2005、VS2008、VS2010)编译在其他编译器下正常通过的C语言程序,你可能会遇到类似如下的警告提示:
引用内容
warning C4996: 'strcpy': This function or variable may be unsafe. Consider using strcpy_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(105) : 参见“strcpy”的声明
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.
1> c:\program files\microsoft visual studio 10.0\vc\include\stdio.h(234) : 参见“fopen”的声明
原因解释
这种微软的警告,主要因为那些C库的函数,很多函数内部是不进行参数检测的(包括越界类的),微软担心使用这些会造成内存异常,所以就改写了同样功能的函数,改写了的函数进行了参数的检测,使用这些新的函数会更安全和便捷。关于这些改写的函数你不用专门去记忆,因为编译器对于每个函数在给出警告时,都会告诉你相应的安全函数,查看警告信息就可以获知,在使用时也再查看一下MSDN详细了解。库函数改写例子:
mkdir改写为 _mkdir
fopen”改写为 fopen_s
stricmp改写为 stricmp_s
strcpy改写为strcpy_s
要学会运用 搜索技术!年轻人!。。