自己实现CstringWord格式文档下载.docx

上传人:b****5 文档编号:20949202 上传时间:2023-01-26 格式:DOCX 页数:26 大小:19.50KB
下载 相关 举报
自己实现CstringWord格式文档下载.docx_第1页
第1页 / 共26页
自己实现CstringWord格式文档下载.docx_第2页
第2页 / 共26页
自己实现CstringWord格式文档下载.docx_第3页
第3页 / 共26页
自己实现CstringWord格式文档下载.docx_第4页
第4页 / 共26页
自己实现CstringWord格式文档下载.docx_第5页
第5页 / 共26页
点击查看更多>>
下载资源
资源描述

自己实现CstringWord格式文档下载.docx

《自己实现CstringWord格式文档下载.docx》由会员分享,可在线阅读,更多相关《自己实现CstringWord格式文档下载.docx(26页珍藏版)》请在冰豆网上搜索。

自己实现CstringWord格式文档下载.docx

TCHAR*Setm_pstr(TCHAR*p_dest);

intGetm_nlen()const;

intGetm_nmax()const;

TCHAR*Getm_pstr()const;

voidDisPlay();

//重载

operatorTCHAR*();

operatorLPCTSTR();

voidoperator=(constTCHARch);

voidoperator=(LPCTSTRp_str);

voidoperator=(constMyCString&

other);

friendMyCStringoperator+(constTCHARch,constMyCString&

friendMyCStringoperator+(LPCTSTRp_str,constMyCString&

other);

friendMyCStringoperator+(constMyCString&

other1,constMyCString&

other2);

voidoperator+=(constTCHARch);

voidoperator+=(LPCTSTRp_dest);

voidoperator+=(constMyCString&

other);

TCHAR&

operator[](intpos);

//查找

intMyFind(constTCHARch,intnstart=0);

intMyFind(LPCTSTRp_dest,intnstart=0);

//替换

intMyReplace(LPCTSTRp_dest,LPCTSTRp_strc);

intMyReplace(constTCHARch,LPCTSTRp_desc);

intMyReplace(LPCTSTRp_desc,constTCHARch);

intMyReplace(constTCHARold_ch,constTCHARnew_ch);

//比较相等为0,大于为1,小于为-1;

intMyCompare(LPCTSTRp_dest);

intMyCompare(MyCString&

intMyCompareNotCase(LPCTSTRp_dest);

//区分大小写

intMyCompareNotCase(MyCString&

//追加在字符串的尾部成功返回当前的长度不成功返回-1;

intMyAppend(constTCHARch);

intMyAppend(LPCTSTRp_str);

intMyAppend(constMyCString&

//大小写转换

voidMyMakeUpper(TCHAR*p_dest);

voidMyMakeLower(TCHAR*p_dest);

//格式化输出

voidMyFormat(TCHAR*fmt,...);

//删除函数

intMyRemove(intn_Start,intn_Num);

//nStart开始处,nNum多少个数

//插入函数

intMyInsert(constTCHARch,intn_Start);

//插入字符,起始位子

intMyInsert(LPCTSTRp_str,intn_Start);

//插入字符串,起始位子

boolMyApply(intn_Num);

TCHAR*Mycpy(TCHAR*pstr,TCHAR*pdes);

intMyStrcmp(LPCTSTRp_str);

intMycmp(TCHAR*str,TCHAR*dst);

//空;

};

#include"

Mycstring.h"

//构造函数

MyCString:

:

MyCString():

m_pstr(NULL),m_nlen(0),m_nmax(0),refCount(NULL)

m_pstr=newTCHAR[NSIZE];

memset(m_pstr,'

\0'

NSIZE);

m_nlen=1;

m_nmax=NSIZE;

refCount=newint

(1);

}

MyCString(constTCHARch):

m_pstr=newTCHAR[1+NSIZE];

1+NSIZE);

m_pstr[0]=ch;

m_nlen+=1;

m_nmax=1+NSIZE;

MyCString(LPCTSTRp_desc):

inti=0;

intj=0;

while(*p_desc!

=NULL&

&

p_desc[i]!

='

i++;

j=i;

m_pstr=newTCHAR[i+NSIZE];

i+NSIZE);

for(;

i>

0;

i--)

{

m_pstr[i-1]=p_desc[i-1];

}

m_nlen=j+1;

m_nmax=m_nlen+NSIZE;

MyCString(constMyCString&

other):

inti=other.m_nlen;

m_pstr=newTCHAR[i+NSIZE];

memset(m_pstr,'

i+NSIZE);

m_nmax=i;

m_nlen=i;

for(;

i>

0;

i--)

m_pstr[i-1]=other.m_pstr[i-1];

refCount=other.refCount;

++*refCount;

m_nmax=other.m_nmax-NSIZE;

//析构函数

~MyCString()

if(--*refCount<

1)

if(m_pstr!

=NULL)

{

delete[]m_pstr;

m_pstr=NULL;

}

m_nlen=0;

m_nmax=0;

voidMyCString:

RefCount()

if(*refCount>

(*refCount)--;

LPCTSTRp=m_pstr;

m_pstr=newchar[m_nmax];

memcpy(m_pstr,p,m_nmax);

intMyCString:

Setm_nlen(intn_Num)

m_nlen=n_Num;

returnm_nlen;

Setm_nmax(intn_Num)

m_nmax=n_Num;

returnm_nmax;

TCHAR*MyCString:

Setm_pstr(TCHAR*p_dest)

returnMycpy(m_pstr,p_dest);

//获取

Getm_nlen()const

Getm_nmax()const

Getm_pstr()const

returnm_pstr;

//输出

DisPlay()

{

cout<

<

"

该字符的详细信息:

endl

<

占有字符为:

Getm_nlen()<

申请空间为:

Getm_nmax()<

字符长度为:

Getm_pstr()<

endl;

//查找

MyFind(constTCHARch,intn_Start)

for(i=n_Start;

i<

m_nlen;

i++)

if(m_pstr[i]==ch)

returni;

return-1;

MyFind(LPCTSTRp_dest,intn_Start)

intj=-1;

intn_len=0;

while(*p_dest!

*p_dest++;

n_len++;

int*next=newint[n_len+1];

next[0]=-1;

while(i<

n_len-1)

if(j==-1||p_dest[i]==m_pstr[j])

{

i++;

j++;

next[i]=j;

else

j=next[j];

i=n_Start;

j=0;

m_nlen-1&

j<

n_len)

delete[]next;

if(j<

=n_len)

returni-n_len-1;

//重载

operatorTCHAR*()

returnm_pstr;

operatorLPCTSTR()

return(LPCTSTR)m_pstr;

operator=(constTCHARch)

operator=(LPCTSTRp_str)

while(p_str!

p_str[i]!

if(i>

m_nmax)

delete[]m_pstr;

m_pstr=NULL;

m_pstr=newTCHAR[i+NSIZE];

m_nmax=i+NSIZE;

m_nmax);

0;

m_pstr[i-1]=p_str[i-1];

m_nlen=j;

operator=(constMyCString&

other)

if(other.m_nlen>

=m_nmax)

delete[]m_pstr;

m_pstr=NULL;

m_pstr=newTCHAR[other.m_nmax];

m_nmax=other.m_nmax;

m_nmax);

for(inti=0;

i<

other.m_nlen;

i++)

m_pstr[i]=other.m_pstr[i];

m_nlen=other.m_nlen;

m_nmax=other.m_nmax;

MyCStringoperator+(constTCHARch,constMyCString&

MyCStringStr(ch);

Str.MyAppend(other);

returnStr;

MyCStringoperator+(LPCTSTRp_str,constMyCString&

MyCStringStr(p_str);

MyCStringoperator+(constMyCString&

other2)

MyCStringStr(other1.m_pstr);

Str.MyAppend(other2.m_pstr);

operator+=(constTCHARch)

MyAppend(ch);

operator+=(LPCTSTRp_dest)

MyAppend(p_dest);

operator+=(constMyCString&

other)

MyAppend(other);

TCHAR&

MyCString:

operator[](intpos)

returnm_pstr[pos];

//比较

MyCompare(LPCTSTRp_dest)

returnMyStrcmp(p_dest);

MyCompare(MyCString&

other)

TCHAR*p=newTCHAR[other.m_nlen];

p[i]=other.m_pstr[i];

p[other.m_nlen]='

;

returnMyStrcmp(p);

//比较不区分

MyCompareNotCase(LPCTSTRp_dest)

while(p_dest!

p_dest[i]!

TCHAR*temp1=newTCHAR[i+NSIZE];

memset(temp1,'

temp1[i-1]=p_dest[i-1];

MyMakeLower(temp1);

while(m_pstr!

m_pstr[j]!

j++;

TCHAR*temp2=newTCHAR[j+NSIZE];

j>

j--)

temp2[j-1]=m_pstr[j-1];

MyMakeLower(temp2);

intn=Mycmp(temp1,temp2);

delete[]temp1;

delete[]temp2;

returnn;

intMyCString:

MyCompareNotCase(MyCString&

while(other.m_pstr!

other.m_pstr[i]!

temp1[i-1]=other.m_pstr[i-1];

temp2[j-1]=other.m_pstr[j-1];

//尾部追加

MyAppend(constTCHARch)

if(m_nlen>

=m_nmax-1)//判断是大于已经申请的范围内

MyApply(0);

RefCount();

m_nlen--;

m_pstr[m_nlen]=ch;

m_nlen++;

m_nmax++;

m_pstr[m_nlen]='

MyAppend(LPCTSTRp_str)

if(p_str==NULL)

return-1;

inti=0;

intj=0;

/*TCHAR*p=NULL;

*/

while(p_str[i]!

='

j=i;

if(m_nlen+i>

m_nmax-1)

MyApply(i);

for(i=m_nlen-1;

m_nlen+j;

m_pstr[i]=p_str[i-m_nlen+1];

m_nlen+=j-1;

m_nmax+=j;

/*m_pstr[m_nlen+1]='

\0;

MyAppend(constMyCString&

if(m_nlen+other.m_nlen>

MyApply(other.m_nlen);

for(inti=0;

=other.m_nlen-1;

i++)

m_pstr[i+m_nlen-1]=other.m_pstr[i];

m_nlen+=other.m_nlen-1;

m_nmax+=other.m_nmax;

//格式化输出;

voidMyCString:

MyFormat(TCHAR*fmt,...)

longl_num;

TCHAR*p_str;

MyCStringother;

intkey;

longi=0;

va_listap;

TCHARch;

va_start(ap,fmt);

//以固定参数的地址为起点确定变参的内存起始地址。

while((ch=*(fmt+i))!

//首先判断print读取到了什么值

if(*(fmt+i)=='

%'

&

*(fmt+i+1)=='

d'

key=1;

++i;

else

if(*(fmt+i)=='

s'

{

key=2;

++i;

}

else

if(*(fmt+i)=='

S'

{

key=4;

++i;

}

else

key=3;

switch(key)

//根据类型进行相应的输出

case1:

l_num=va_arg(ap,int);

cout<

l_num;

break;

case2:

p_str=va_arg(ap,TCHAR*);

p_str;

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 高等教育 > 艺术

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1