首页 技术 正文
技术 2022年11月14日
0 收藏 452 点赞 5,070 浏览 2235 个字

memcpy() — 拷贝内存内容

相关函数: bcopy(), memccpy(), memmove(), strcpy(), strncpy()
表头文件: #include <string.h>
定义函数: void *memcpy(void *dest, const void *src, size_t n)
函数说明: memcpy()用来拷贝src所指的内存内容前n个字节到dest所指的内存地址上。与strcpy()不同的是,memcpy()会完整的复制n个字节,不会因为遇到字符串结束’\0’而结束
返回值:   返回指向dest的指针
附加说明: 指针src和dest所指的内存区域不可重叠

   1:  #include <string.h>
   2:  #include <stdio.h>
   3:   
   4:  int main()
   5:  {
   6:      char a[30] = "string (a)";
   7:      char b[30] = "hi\0zengxiaolong";
   8:      int i;
   9:   
  10:      strcpy(a, b);             //a[30] = "hi\0ing (a)"
  11:      printf("strcpy():");
  12:      for(i = 0; i < 30; i++)
  13:          printf("%c", a[i]);   //hi ing (a)
  14:   
  15:   
  16:      memcpy(a, b, 30);         //a[30] = "hi\0zengxiaolong"
  17:      printf("\nmemcpy():");
  18:      for(i = 0; i < 30; i++)
  19:          printf("%c", a[i]);   //hi zengxiaolong
  20:      printf("\n i = %d\n", i); //30
  21:   
  22:  }

.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, “Courier New”, courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }

iterator是C++标准库(STL)中的迭代器~~~

比如你建一链表(要记得#include <list>

#include <iostream>)

list<char> A;

再list<char>::iterator it,这样,就可以对链表进行遍历了~

其实,你可以把它理解成类似指针的东西~当然,只是用处差不多,使用方式和声明方式可是完全不同的喔~~

PS:再给你一个简单的小

程序段,可以说明iterator的用处~

   1:  #include <list> 
   2:  #include <iostream> 
   3:  using namespace std;
   4:   
   5:  void main(void) 
   6:  { 
   7:  int a[]={1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; 
   8:  list<int> name(a,a+10); 
   9:   
  10:  list<int>::iterator it; 
  11:  for (it = name.begin(); it != name.end(); it++) 
  12:  { 
  13:  cout << *it << endl;   //就是可以指向容器中元素的东西,就好像指针那样,但是它不是指针。
  14:  } 
  15:  } 

.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, “Courier New”, courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,088
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,565
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,413
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,186
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,822
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,905