有个C++问题 请高手写详细一点 谢谢了 要完整的一个程序 在线等

来源:百度知道 编辑:UC知道 时间:2024/09/21 19:56:24
完善自定义字符串mystring,函数包括构造函数,复制构造函数,析构函数,并重载运算符“【】”,"="(分别用mystring和C字符串复制),“+”(strct),"+=","<",">","==“(strcmp)。

自己检查下有没有错误。

// MyString.h

#define BUFFSIZE 100

class MyString
{
public:
MyString(const MyString &other);
MyString(const char *str);
MyString();
~MyString();

bool operator==(const MyString &other) const;
bool operator<(const MyString &other) const;
bool operator>(const MyString &other) const;
MyString &operator=(const MyString &other);
MyString &operator+=(const MyString &other);
MyString operator+(const MyString &other);
char &operator[](int i);

private:
int m_strlen;
char *m_buffer;
};

#include <iostream>
#include <cstring>
#include <cstdio>

using namespace std;

#include "MyString.h"

MyString::MyString()
{
m_buffer = new char[BUFFSIZE + 1];

if (!m_buffer)
{
cerr << "Memory Alloc Failed!" << endl;