字符串类String重载操作Word文件下载.docx
- 文档编号:13166996
- 上传时间:2022-10-07
- 格式:DOCX
- 页数:3
- 大小:31.25KB
字符串类String重载操作Word文件下载.docx
《字符串类String重载操作Word文件下载.docx》由会员分享,可在线阅读,更多相关《字符串类String重载操作Word文件下载.docx(3页珍藏版)》请在冰豆网上搜索。
45.定义一个字符串类String,用来存放不定长的字符串,重载运算符"
>
,用于两个字符串的大于的比较运算。
#include<
iostream>
string>
usingstd:
:
string;
classString
{
private:
char*p;
public:
String()
{
p=NULL;
}
String(char*pp)
p=pp;
friendbooloperator==(String&
a,String&
b);
friendbooloperator>
(String&
a,String&
friendbooloperator<
voiddisplay()
std:
cout<
p;
};
booloperator==(String&
b)
if(strcmp(a.p,b.p)==0)
returntrue;
else
returnfalse;
}
booloperator>
if(strcmp(a.p,b.p)>
0)
booloperator<
if(strcmp(a.p,b.p)<
voidcompare(Stringa,Stringb)
if(operator>
(a,b))
a.display();
"
;
b.display();
elseif(operator<
=="
voidmain()
Stringstring("
abc"
);
Stringstring1("
abcs"
compare(string,string1);
system("
pause"
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 字符串 String 重载 操作
![提示](https://static.bdocx.com/images/bang_tan.gif)