代码拉取完成,页面将自动刷新
include<iostream>
using namespace std;
class Mystring
{
private:
char str[1024];
unsigned len;
public:
Mystring() { len = 0; };
Mystring& operator =(const char* str1)
{
int i = 0;
for (i = 0; i < 1024&&str1[i]!='\0'; i++)
{
str[i] = str1[i];
len++;
}
return *this;
}
friend ostream& operator <<(ostream& out, Mystring good)
{
int j = 0;
for (j = 0; j <good. len; j++)
{
out << good.str[j];
}
return out;
}
Mystring& operator=(const Mystring good)
{
len = good.len;
int i = 0;
for (i = 0; i < len; i++)
{
str[i] = good.str[i];
}
return *this;
}
Mystring& operator+(const Mystring good)
{
int j = len;
len = len + good.len;
int i = 0;
for (j; j < len; j++)
{
str[j] = good.str[i];
i++;
}
return *this;
}
char &operator[](int a)
{
return str[a];
}
bool operator==(const Mystring good)
{
if (good.len != len)
{
return false;
}
int i = 0;
for (i = 0; i < len; i++)
{
if (str[i] != good.str[i])
{
return false;
}
}
return true;
}
bool operator!=(Mystring good)
{
if (good.len != len)
{
return true;
}
int i = 0;
for (i = 0; i < len; i++)
{
if (str[i] == good.str[i])
{
return false;
}
}
return true;
}
/*bool operator==(const Mystring mstr) {
if (len != mstr.len) {
return false;
}
for (int i = 0; i < len; i++) {
if (str[i] != mstr.str[i]) {
return false;
}
}
return true;
}*/
/*bool operator!=(const Mystring mstr) {
return !(*this == mstr);
}*/
Mystring& operator+=(const Mystring good)
{
int i = len;
len = len + good.len;
int j = 0;
for (i; i < len; i++)
{
str[i] = good.str[j];
j++;
}
return *this;
}
bool operator>(const Mystring good)
{
int i;
int j;
if (len <= good.len)
{
i = len;
j = 0;
}
else
{
i = good.len;
j = 1;
}
int k = 0;
for (k = 0; k < i; k++)
{
if (str[k] > good.str[k])
{
return true;
}
else if (str[k] < good.str[k])
{
return false;
}
else
{
}
}
if (j == 0)
{
return false;
}
else
{
return true;
}
}
bool operator<(const Mystring good)
{
int i;
int j;
if (len <= good.len)
{
i = len;
j = 0;
}
else
{
i = good.len;
j = 1;
}
int k = 0;
for (k = 0; k < i; k++)
{
if (str[k] < good.str[k])
{
return true;
}
else if (str[k] > good.str[k])
{
return false;
}
else
{
}
}
if (j == 0)
{
return true;
}
else
{
return false;
}
}
};
int main()
{
char ts[1024];
cin >> ts;
Mystring s;
s = ts;
cin >> ts;
Mystring ss;
ss = ts;
if (ss == s)
cout << "equal" << endl;
if (ss != s)
{
cout << "Not equal" << endl;
if (s > ss)
cout << "s da yu ss" << endl;
if (s < ss)
cout << "s xiao yu ss" << endl;
}
ss += s;
Mystring sss;
sss = s + ss;
sss[0] = '$';
cout << sss << endl;
return 0;
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。