C++字符串处理函数学习笔记
2013-08-07 17:21
573 查看
1. memcpy <cstring>
定义:
[/code]
[/code]
定义:
void * memcpy ( void * destination, const void * source, size_t num );
功能:
从source指定的内存块中复制num字节的数据到destination指定的内存块中。在本函数中,不关注由source和destination指定的相关对象的类型;函数返回结果为相应的二进制数据的副本。
本函数不检查source中的任何终止字符,它总是完全复制从source开始的num个字节的数据。
示例:
/* memcpy example */ #include <stdio.h> #include <string.h> struct { char name[40]; int age; } person, person_copy; int main () { char myname[] = "Pierre de Fermat"; /* using memcpy to copy string: */ memcpy ( person.name, myname, strlen(myname)+1 ); person.age = 46; /* using memcpy to copy structure: */ memcpy ( &person_copy, &person, sizeof(person) ); printf ("person_copy: %s, %d \n", person_copy.name, person_copy.age ); return 0; }原文:memcpy[/code]
2. memmove <cstring>定义:从source指定的位置开始复制num字节的数据到destination指定的内存块。本函数允许source和destination中间有重叠的缓存。[/code]void * memmove ( void * destination, const void * source, size_t num );[code]功能:
本函数不检查source中的任何终止字符,它总是完全复制从source开始的num个字节的数据。
示例:
/* memmove example */ #include <stdio.h> #include <string.h> int main () { char str[] = "memmove can be very useful......"; memmove (str+20,str+15,11); puts (str); return 0; }
原文:memmove
[/code]
3. strcpy <cstring>定义:[code] char * strcpy ( char * destination, const char * source );
功能:
将由source指定的C-串(包括终止符)复制到由destination指定的数组。为了避免溢出,由destination指定的应该足够长,以容纳由source指定的C-串的所有内容(包括终止符),并且destination的内存不能和source重叠。
示例:
/* strcpy example */ #include <stdio.h> #include <string.h> int main () { char str1[]="Sample string"; char str2[40]; char str3[40]; strcpy (str2,str1); strcpy (str3,"copy successful"); printf ("str1: %s\nstr2: %s\nstr3: %s\n",str1,str2,str3); return 0; }
[/code]
原文:strcpy
相关文章推荐
- C/C++学习笔记29:字符串处理函数
- PHP字符串处理函数示例学习笔记
- Flex与As3学习笔记之:Part 3 函数参数、字符串处理、日期与时间类型
- C/C++语言函数学习(4)字符串处理函数
- 【C++】学习笔记三十三——函数和C风格字符串
- C++学习笔记-----operator=函数处理自赋值
- 学习笔记之10-字符和字符串常用处理函数
- C++学习笔记之函数如何返回字符串(char型)
- C/C++学习笔记:字符串库函数
- C++学习笔记之函数如何返回字符串(char型)
- 【C++学习笔记】string类处理字符串的一些特点
- 学习笔记PHP字符串处理函数总结
- php学习笔记(五)字符串及其相关处理函数
- Linux C学习笔记 —— 字符串处理函数(string.h)
- C++学习笔记六之函数如何使用指针来处理数组?
- C语言学习笔记之常用的字符串处理函数
- C语言学习笔记 lesson17 字符串处理函数之fgets与gets
- C++ FAQ学习笔记 17章 异常和错误处理
- C++学习笔记1(带参数的main( )函数)
- c++学习笔记:lambda函数