#include <iostream>
#include <string>
#include <cstring>
using namespace std;
class mystring
{
public:
mystring() = default;
mystring(const char* pstr)
{
str = new char[strlen(pstr) + 1];
strcpy(str, pstr);
}
~mystring()//析构
{
delete[]str;
str = nullptr;
}
mystring(const mystring& ms)
{
str = new char[strlen(ms.str) + 1];
strcpy(str, ms.str);
}
void print()
{
cout << str << endl;
}
char* myc_str()//有'\0'的
{
char* temp = new char[strlen(str) + 1];
strcpy(temp, str);
return temp;
}
char* mydata()//无'\0'
{
char* temp = new char[strlen(str)];
strcpy(temp, str);
return temp;
}
char* myapp(const mystring& boy)//追加
{
char* temp = new char[strlen(str) + strlen(boy.str)];
strcpy(temp, str);
strcpy(temp + strlen(str), boy.str);
return temp;
}
int mycompare(const mystring& boy)//大于返回1,小于返回-1,等于返回0
自实现字符串的追加和比较
最新推荐文章于 2024-07-26 10:10:33 发布