读书人

strcpy中你想不到的有关问题

发布时间: 2012-03-24 14:00:46 作者: rapoo

strcpy中你想不到的问题!
你觉得下面一段代码能正确执行吗?为什么?
int main()
{
char* src= "hello world! ";
char deststd[5];
strcpy(deststd,src);
printf( "%s\n ",deststd);
}

[解决办法]
Remarks
The strcpy function copies strSource, including the terminating null character, to the location specified by strDestination. The behavior of strcpy is undefined if the source and destination strings overlap.

Security Note Because strcpy does not check for sufficient space in strDestination before copying strSource, it is a potential cause of buffer overruns. Consider using strncpy instead.
wcscpy and _mbscpy are wide-character and multibyte-character versions of strcpy. The arguments and return value of wcscpy are wide-character strings; those of _mbscpy are multibyte-character strings. These three functions behave identically otherwise.

读书人网 >C++

热点推荐