冬天¤不回来
海风轻轻吹过我的脸庞 阳光温柔的洒在我身上 海鸥自由的飞在天空中像 快乐的徘徊在游乐场 白云在偷看彩虹的模样 海洋总为那船长指方向 海浪抚摸著沙滩的衣裳 我也每天都为他换上新装 找到方向 揭开迷茫 学着坚强 努力去闯!
posts - 20,  comments - 90,  trackbacks - 0

#ifndef CMyString

#define CMyString

#define max_string_size 1024                                 //第一串的最大长度为1024

class CMyString
{
private:
 int length;                                               //字符串的实际长度
 
 char str[max_string_size+1];                              //包括最后的结束符 字符串的存处空间;
public:
 
 CMyString();
 
    CMyString(const char * s);                                //构造一个字符指针所指的对象
 
 ~CMyString();
 
 concatenate(const concatenate *s);                                //将字符串S插入到本字符串之后
 
 insert(const int pos, const CMyString *s);                 //将字符串插入到本字符串POS所指的位置
 
 delete(const int pos, const int len);                      //删除从POS位置起的连续len个字符
   
 CMyString substring(const int pos, cont int len);          //从pos位置起 提取一个长度为len的子串

 char *getstring();                                                  //获取本字符串

 int getstring();                                                         / /获取字符串长度

 int find(const CMyString *s);                               //在字符串中查找S首次出现的位置,如不包含S 则返回0;
   
};
#endif



//////////////////////////////串类的实现/////////////////////////////////////////


#include<iostream.h>

#include"CMyString.h"

#include"memory.h"

#include"stdafx.h"                    //不懂 stdafx.h 是什么意思


CMyString::CMyString()
{
 length=0;
 str[0]=0;
}


//////////////////构造2//////////
CMyString::CMyString(const char *s)                     
{
 char *p1,*p2;
 for(length=0,p1=str,p2=(char *)s;  *p2;  length++)
  *p1++ = *p2++;
 *p1=0;
}


/////////////////////析够//////////
CMyString::~CMyString()
{}

 

//////////////将字符串S插入到本字符串之后//////////////
CMyString::concatenate(const concatenate *s)
{
 if(length+s ->length <= max_string_size+1)
 {
  mencpy(str+length, s->str .s->length+1);
  length += s->length;
 }
 else
 {
  cout<<"error"<<endl;
 }
}


////////////删除从POS位置起的连续len个字符///////
CMyString::delete(const int pos, const int len)
{
 int rlen = len;
 if(pos +rlen > length)]
  rlen = length - pos;
 length -= rlen;
 memcpy( str +pos,str+pos+rlen, length - pos+1);
}


/////////////////在字符串中查找S首次出现的位置,如不包含S 则返回0///////////////
int CMyString::find(const CMyString *s)
{
 ..
}

 

////////////////获取字符串长度/////////
int CMyString::getlegth()
{
 return length;
}

char *CMyString::getstring()

{
 char *tmpstr = new char[length+1];
 memcpy(tmpstr , str ,length +1);
 return tmpstr;
}


////////////////将字符串插入到本字符串POS所指的位置/////////
CMyString::insert(const int pos, const CMyString *s)
{
 if(length + s -> length <= max_string_size)
 {
  memcpy(str + pos + s -> length, str+pos,length-pos+1);
  memcpy(str+pos,s->str,s->length);
  length +=s ->length;
 }
 else
 {
  cout<<"error"<<endl;
 }
}


/////////////////从pos位置起 提取一个长度为len的子串//////////
CMyString CMyString::substring(const int pos,const int len)
{
 int rlen = len;
 CMyString tmpstr("");
 if(pos +len >length)
  rlen = length - pos;
 memcpy(tmpstr.str,str+pos,len);
 tmpstr.length = rlen;
 tmpstr.str[tmpstr.length] = 0;
 return tmpstr;
}

posted on 2006-10-08 21:06 冬天¤不回来 阅读(525) 评论(0)  编辑 收藏 引用

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理


QQ:41696402

<2006年10月>
24252627282930
1234567
891011121314
15161718192021
22232425262728
2930311234

常用链接

留言簿(3)

随笔档案

文章档案

Programming

最新随笔

搜索

  •  

积分与排名

  • 积分 - 38464
  • 排名 - 534

最新评论

阅读排行榜

评论排行榜