#include "stdafx.h"
#include <iostream>
#include <iomanip>
#include <cassert>
using namespace std;
void* MyMemcpy(void* target, const void* source, size_t n)
{
const char* source_p = (const char*)source;
char* target_p = (char*)target;
while(n--)
*target_p++ = *source_p++;
return target;
}
int _tmain(int argc, _TCHAR* argv[])
{
char* source = "Shenzhen,China!";
size_t sLen = strlen(source);
char* target = new char[sLen+1];
assert(target != NULL);
target[0] = '\0';
cout << "before copy:" << endl;
cout << "source: " << source <<endl;
cout << "target: " << target <<endl;
MyMemcpy(target,source,sLen);
target[sLen]='\0';
cout << "after copy:" << endl;
cout << "source: " << source <<endl;
cout << "target: " << target <<endl;
delete []target;
/*
输出:
before copy:
source: Shenzhen,China!
target:
after copy:
source: Shenzhen,China!
target: Shenzhen,China!
请按任意键继续. . .
*/
system("pause");
return 0;
}
MyMemcpy
最新推荐文章于 2023-10-19 13:17:59 发布