#include<iostream>
#include <string>
using namespace std;
class MyString
{
private:
char *s;
public:
MyString(const char *str = NULL);
MyString(const MyString &other);
MyString & operator=(const MyString &other);
~MyString();
};
MyString::MyString(const char *str)
{
if (str == NULL)
{
s = new char[1];
*s = '\0';
}
else
{
s = new char[strlen(str) + 1];
strcpy(s,str);
}
}
MyString::MyString(const MyString &other)
{
if (other.s == NULL)
s = NULL;
int len = strlen(other.s);
s = new char[len + 1];
strcpy(s,other.s);
}
MyString &MyString::operator=(const MyString &other)
{
if (&other == this)
return *this;
if (s!=NULL)
delete [] s;
int len = strlen(other.s);
s = new char[len + 1];
strcpy(s, other.s);
return *this;
}
MyString::~MyString()
{
if (s!=NULL)
delete [] s;
}
int main(void)
{
return 0;
}
#include <string>
using namespace std;
class MyString
{
private:
char *s;
public:
MyString(const char *str = NULL);
MyString(const MyString &other);
MyString & operator=(const MyString &other);
~MyString();
};
MyString::MyString(const char *str)
{
if (str == NULL)
{
s = new char[1];
*s = '\0';
}
else
{
s = new char[strlen(str) + 1];
strcpy(s,str);
}
}
MyString::MyString(const MyString &other)
{
if (other.s == NULL)
s = NULL;
int len = strlen(other.s);
s = new char[len + 1];
strcpy(s,other.s);
}
MyString &MyString::operator=(const MyString &other)
{
if (&other == this)
return *this;
if (s!=NULL)
delete [] s;
int len = strlen(other.s);
s = new char[len + 1];
strcpy(s, other.s);
return *this;
}
MyString::~MyString()
{
if (s!=NULL)
delete [] s;
}
int main(void)
{
return 0;
}