码迷,mamicode.com
首页 > 其他好文 > 详细

memcpy 的内存拷贝函数

时间:2018-08-23 19:32:34      阅读:142      评论:0      收藏:0      [点我收藏+]

标签:int   nbsp   --   color   psr   col   end   cout   void   

 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 的内存拷贝函数

标签:int   nbsp   --   color   psr   col   end   cout   void   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!