#include <iostream>
using namespace std;
int main( void )
{
const size_t SIZE = 5;
const char NULL_TERMINATED = '\0';
char buf[128];
memcpy( buf, "123456789", SIZE );
//buf[SIZE] = NULL_TERMINATED; //第一次没有末尾置零操作
cout << buf << endl;
cout << strlen( buf ) << endl;
cout << "" << endl;
memcpy( buf, "123456789", SIZE );
buf[SIZE] = NULL_TERMINATED; //第二次进行末尾置零操作
cout << buf << endl;
cout << strlen( buf ) << endl;
system( "PAUSE" );
return EXIT_SUCCESS;
}
/*-------------------
12345?
7
12345
5
请按任意键继续. . .
结论:
memcpy()函数没有在串结尾添加结束符
---------------------------------*/
测试memcpy()函数有没有在串结尾添加结束符
最新推荐文章于 2024-05-17 11:38:51 发布