易截截图软件、单文件、免安装、纯绿色、仅160KB

C/C++风格字符串

一:字符串类型分类:
1.       C风格字符串:起源于C,并在C++中得到支持。
a.       存储方式:被存储在一个字符数组中,通过一个char*类型的指针来操纵它。
b.       提供的库函数:包含头文件:#include<cstring>
a)         int strlen( const char* );//返回字符串的长度
b)        int strcmp( const char*, const char* );//比较两个字符串是否相等
c)        char* strcpy( char*, const char* );//把第二个字符串拷贝到第一个字符串中
#include <iostream>
#include <cstring>
#include <stdio.h>
using namespace std;
void main()
{
    char* arraya = "hello world!";
    int c;
    c = strlen(arraya);
    cout<<c<<endl;
    char arrayb[80];
    char * test = NULL;
    test = strcpy (arrayb, arraya);
    cout<<"test is: "<<test<<endl;
    cout<<arrayb<<endl;
    int d;
    d = strcmp(arrayb,arraya);
    cout<<endl<<"d->"<<d<<endl;
}这段代码包含了以上三个库函数的使用。
二:c++风格的string
1.       我们使用string,它的库函数有很多,当我们需要获得某个字符串的长度的时候,可以调用size()函数:
这里我们定义一个string:string sa = “hello world!”;
1)  我们调用size()函数:sa.size();它的值就是12;
2)  我们需要判断一个字符串是否为空的时候,我们可以调用empty()函数来判断:sa.empty();若这个字符串为空,那么它将返回1,若不为空,则返回0。
3)  我们会用到拷贝字符串的情况,在我们初始化一个字符串的时候,我们可以初始化成一个字符串的拷贝:string sc(sa);在这段代码后,sc的内容和sa就完全相同了。我们可以使用一个判断语句来判断这两个字符串是否相等:if( sc == sa)…
&nb


相关文档:

航空公司管理系统(VC++ 与SQL 2005)

系统环境:Windows 7
软件环境:Visual C++ 2008 SP1 +SQL Server 2005
本次目的:编写一个航空管理系统
      这是数据库课程设计的成果,虽然成绩不佳,但是作为我用VC++ 以来编写的最大程序还是传到网上,以供参考。用VC++ 做数据库设计并不容易,但也不是不可能。以下是我的程序界面,后面 ......

C++解析XML

用mingw32-make前修改一下makefile文件,改为如下
# DEBUG can be set to YES to include debugging info, or NO otherwise(不是DEBUG)
DEBUG          := NO
# PROFILE can be set to YES to include profiling info, or NO otherwise
PROFILE    & ......

C发声程序

#include "stdafx.h"
#include <stdio.h>
#include <windows.h>
#include <math.h>
#include <conio.h>
typedef struct {
      short int pitch;
      short int duration;
} NOTE;
NOTE notes[] = {{14, 500}, {16, 500}, {12, 500 ......

什么才叫精通C/C++


It is better to have the ability of fast learning
有一天你覺得甚麼都知道了   可悲
有一天你卻發現你甚麼都不會 加油吧
有一天你發現你又甚麼都會了 繼續
有一天你發現你甚麼都不會了 成功了 ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号