字符串类String重载操作.docx

上传人:wj 文档编号:1308340 上传时间:2023-04-30 格式:DOCX 页数:3 大小:31.25KB
下载 相关 举报
字符串类String重载操作.docx_第1页
第1页 / 共3页
字符串类String重载操作.docx_第2页
第2页 / 共3页
字符串类String重载操作.docx_第3页
第3页 / 共3页
亲,该文档总共3页,全部预览完了,如果喜欢就下载吧!
下载资源
资源描述

字符串类String重载操作.docx

《字符串类String重载操作.docx》由会员分享,可在线阅读,更多相关《字符串类String重载操作.docx(3页珍藏版)》请在冰点文库上搜索。

字符串类String重载操作.docx

43.定义一个字符串类String,用来存放不定长的字符串,重载运算符“==”,,用于两个字符串的等于比较运算。

初值自拟。

44.定义一个字符串类String,用来存放不定长的字符串,重载运算符"<",用于两个字符串的小于的比较运算。

初值自拟。

45.定义一个字符串类String,用来存放不定长的字符串,重载运算符">",用于两个字符串的大于的比较运算。

初值自拟。

#include

#include

usingstd:

:

string;

classString

{

private:

char*p;

public:

String()

{

p=NULL;

}

String(char*pp)

{

p=pp;

}

friendbooloperator==(String&a,String&b);

friendbooloperator>(String&a,String&b);

friendbooloperator<(String&a,String&b);

voiddisplay()

{

std:

:

cout<

}

};

booloperator==(String&a,String&b)

{

if(strcmp(a.p,b.p)==0)

{

returntrue;

}

else

{

returnfalse;

}

}

booloperator>(String&a,String&b)

{

if(strcmp(a.p,b.p)>0)

{

returntrue;

}

else

{

returnfalse;

}

}

booloperator<(String&a,String&b)

{

if(strcmp(a.p,b.p)<0)

{

returntrue;

}

else

{

returnfalse;

}

}

voidcompare(Stringa,Stringb)

{

if(operator>(a,b))

{

a.display();

std:

:

cout<<">";

b.display();

}

elseif(operator<(a,b))

{

a.display();

std:

:

cout<<"<";

b.display();

}

else

{

a.display();

std:

:

cout<<"==";

b.display();

}

}

voidmain()

{

Stringstring("abc");

Stringstring1("abcs");

compare(string,string1);

system("pause");

}

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

当前位置:首页 > 求职职场 > 简历

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2