C++编写一个自定义字符串类mystring

完善以下函数

#include <iostream>
using namespace std;
const int maxsize = 256;
class mystring
{
    char str[maxsize];
    int len;
public:
    mystring()
    {
        len = 0;
        str[0] = '\0';
        cout << "缺省构造函数" << endl;
    }
    mystring(char* s)
    {
        ...//要完善的部分
        cout << "构造函数(用C风格字符串初始化)" << endl;
    }
}//复制构造函数
mystring(mystring& ms)
{
    ...//要完善的部分
    cout << "拷贝构造函数" << endl;
}
~mystring()
{
    cout << "析构函数" << endl;
}
void show()
{ //打印字符串
    ...//要完善的部分
}
};
int main()
{
    char str[21] = "Hello C++";
    mystring A(str);
    mystring B = A;
    A.show();
    return 0;
}

img


#include <iostream>
using namespace std;
const int maxsize = 256;
class mystring
{
    char str[maxsize];
    int len;
public:
    mystring()
    {
        len = 0;
        str[0] = '\0';
        cout << "缺省构造函数" << endl;
    }
    mystring(char* s)
    {
        //...//要完善的部分
        int i=0;
        for(i=0;s[i]!='\0';i++)
        {
            str[i]=s[i];
        }
        len=i;
        cout << "构造函数(用C风格字符串初始化)" << endl;
    }
//复制构造函数
mystring(mystring& ms)
{
    //...//要完善的部分
    len=ms.len;
    for(int i=0;i<len;i++)
    {
        str[i]=ms.str[i];
    }
    cout << "拷贝构造函数" << endl;
}
~mystring()
{
    cout << "析构函数" << endl;
}
void show()
{ //打印字符串
    //...//要完善的部分
    for(int i=0;i<len;i++)
   {
        cout<<str[i];
    }
    cout<<'\n';
}
};
int main()
{
    char str[21] = "Hello C++";
    mystring A(str);
    mystring B = A;
    A.show();
    return 0;
}