strcpy是拷贝字符串,以\0为标志结束(即一旦遇到数据值为0的内存地址拷贝过程即停止) strcpy的原型为 char *strcpy(char *dest, const char *src) 而memcpy是给定来源和目标后,拷贝指定大小n的内存数据,而不管拷贝的内容是什么
1#include <iostream>2#include <cstring>3usingnamespacestd;45intmain ()6{7charstr[] ="almost every programmer should know memset!";8memset (str,'-',6);9cout<<str;10return0;11} Output: 1--- every programmer should know memset! memcpy Copy block of memory <cstring> void * memcpy ( ...
memset Fill block of memory <cstring> void * memset ( void * ptr, int value, size_t num );Sets the first num bytes of the block of memory pointed by ptr to the specified value (interpreted as an unsigned char).Parameters ptr Pointer to the block of memory to fill.value ...
1#include <iostream>2#include <cstring>3usingnamespacestd;45intmain ()6{7charstr[] ="almost every programmer should know memset!";8memset (str,'-',6);9cout<<str;10return0;11} Output: 1--- every programmer should know memset! memcpy Copy block of memory <cstring> void * memcpy ( ...