c/c++ string
1.本章思维导图:
Example1:
char
*strcpy(char *target, const char *source) {
char *t = target;
// Copy the contents of source into target.
while(*source) *target++ = *source++;
// Null-terminate the
target.
*target = '\0';
// Return pointer to the
start of target.
return t;
}
Example2:
void
*memmove(void *target, const void *source, size_t count)
这个函数即使
是在源和目的字符串有所重叠时操作也能成功,虽然source为const,但是其指向的array也可能被修改。
2.
C型字符串操作实例:
Ex1.基本操作
/*
*
=====================================================================================
*
* Filename: 2-1.cpp
*
*
Description: Fundamental Operations in C Type String
*
*
Version: 1.0
* Created: 05/11/2010 10:43:11 AM
*
Revision: none
* Compiler: gcc
*
*
Author: gnuhpc (http://blog.csdn.net/gnuhpc)
,
warmbupt@gmail.com
* Company: IBM CDL
*
*
=====================================================================================
*/
#include
#include
using namespace std;
int main(int argc, char *argv[])
{
char strA[7]="UP";
char strB[5]="DOWN";
char strC[5]="LEFT";
char strD[6]="RIGHT";
/*Display */
cout << "Here are the strings: " <<
endl;
相关文档:
如何交换两个变量的值:
C语言中的传值代码如下:
int change(int x,int y)
{
int temp=x;
x=y;
y=temp;
}
C语言中的传址代码如下:
int change(int *p,int *q)
{
int temp=*p;
*p=*q;
*q=temp;
}
使用C++中的引用类型代码如下:
int change(int &x,int &y)
{
int temp=x;
x=y;
y=temp;
}
JAV ......
对于一个c/c++程序员来说,内存泄漏是一个常见的也是令人头疼的问题。已经有许多技术被研究出来以应对这个问题,比如Smart Pointer,Garbage Collection等。Smart Pointer技术比较成熟,STL中已经包含支持Smart Pointer的class,但是它的使用似乎并不广泛,而且它也不能解决所有的问题;Garbage Collection技术在Java中 ......
C、传统 C++
#include <stdio.h> //定义输入/输出函数
#include <stdlib.h> //定义杂项函数及内存分配函数
#include <string.h> //字符串处理
#include <assert.h> //设定插入点
#include <ctype.h> //字符处理
#include <errno.h&g ......
developerWorks 中国 > Linux > 用 C99 进行开放源代码的开发您的 C 代码符合标准吗? 文档选项 打印本页 将此页作为电子邮件发送 级别: 初级 Peter Seebach (developerworks@seebs.plethora.net), 自由作家 2004 年 4 月 01 日 C99 是什么?谁需要它?它可用了吗?Poter Seebach 讨论了 ISO C 标准的 1999 年修订版 ......
C和C++的点滴积累(1)
1. mfc 编程中存在着如果出现“内存不足”的对话框,一种情况是在申请内存的时候出现问题,也就是例如:char *pChar = new char[num]; 但此时num 为零或者负 ......