报了三个警告,能分析一下原因不?
#include<iostream>
using namespace std;
int main()
{
const char *cp1="A string example";
const char *cp2="A different string";
char largeStr[16+18+2];
strncpy(largeStr,cp1,17);
strncat(largeStr," ",2);
strncat(largeStr,cp2,19);
for(char *pbegin=largeStr,*pend=largeStr+sizeof(largeStr)/sizeof(char);pbegin!=pend;++pbegin)
cout<<*pbegin;
return 0;
}
运行了,有三个警告,能分析一下原因不?
[解决办法]
将strncpy改为strncpy_s,将strncat改为strncat_s,就没有警告了
[解决办法]
f:\cppprogram\test\test\test.cc(8) : warning C4996: 'strncpy': This function or variable may be unsafe. Consider using strncpy_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.1> d:\program files\microsoft visual studio 9.0\vc\include\string.h(157) : 参见“strncpy”的声明1>f:\cppprogram\test\test\test.cc(9) : warning C4996: 'strncat': This function or variable may be unsafe. Consider using strncat_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.1> d:\program files\microsoft visual studio 9.0\vc\include\string.h(144) : 参见“strncat”的声明1>f:\cppprogram\test\test\test.cc(10) : warning C4996: 'strncat': This function or variable may be unsafe. Consider using strncat_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.1> d:\program files\microsoft visual studio 9.0\vc\include\string.h(144) : 参见“strncat”的声明1>正在编译资源清单...
[解决办法]
还是提倡用string吧···不容易出错···