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++这样自由度非常大的编程语言,几乎是每一个用其开发出来的软件都会出现内存泄漏的情况。
如果没有内存泄漏,世界或许会变的美好。然而,完全美好的世界是不存在的,我们能做的就是尽量让它变的更美 ......
总是被同学们问到,如何学习C和C++才不茫然,才不是乱学,想了一下,这里给出一个总的回复。
一家之言,欢迎拍砖哈。
1、可以考虑先学习C。
大多数时候,我们学习语言的目的,不是为了成为一个语言专家,而是希望成为一个解决问题的专家。做一个有用的程序员,做一个赚钱的程序员。我们的价值,将体现在客户价值上,而不 ......
用VC++6.0编写了一个简单的dll,里面包含一个减法函数subtract(int a,int b),Dll命名为ff.Dll
代码如下:
1.ff.cpp:
// ff.cpp : Defines the entry point for the DLL application.
//
#include "StdAfx.h"
#include "ff.h"
BOOL APIENTRY DllMain( HANDLE hModule,
......