首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

strcpy中你想不到的有关问题

2012-03-24 
strcpy中你想不到的问题!你觉得下面一段代码能正确执行吗?为什么?intmain(){char*src helloworld!char

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.

热点排行