首页 > 其他 > 详细

memcpy 的内存拷贝函数

时间:2018-08-23 19:03:10      阅读:160      评论:0      收藏:0      [点我收藏+]
 1 #include <iostream>
 2 
 3 using namespace std;
 4 
 5 void *memory(void *dst,const void *src,size_t s)
 6 {
 7 
 8    const char* psrc=static_cast<const char*>(src);
 9     char* pdst=static_cast<char*>(dst);
10 
11     if(psrc==NULL||pdst==NULL)
12         return NULL;
13 
14     if(pdst>psrc&&pdst<(psrc+s))
15     {
16         for(size_t i=s-1;i!=-1;i--)
17             pdst[i]=psrc[i];
18     }
19     else
20     {
21         for(size_t i=0;i<s;++i)
22             pdst[i]=psrc[i];
23     }
24     return dst;
25 }
26 int main()
27 {
28    char buf[100]="abcdefghijk";
29    cout << buf << endl;
30    memory(buf+2,buf,5);
31    cout << buf;
32    return 0;
33 }

 

memcpy 的内存拷贝函数

原文:https://www.cnblogs.com/mingyoujizao/p/9525130.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!