High School/Jr. High
New professional
for(i = 0; i < 2; ++i)
printf (“%s”, message[i]);
printf (“\n”);
}
class string
{
private:
int size;
char *ptr;
public:
string ( ) : ptr (new char(‘\0’)) {}
string (const string &s) : size (s.size)
{
ptr = new char[size + 1];
strcpy (ptr, s.ptr);
}
~string( )
{
delete [ ] ptr;
}
friend ostream &operator << (ostream
&, const string &);
string &operator = (const char *);
}
ostream &operator << (ostream &stream,
const string &s)
{
return (stream << s.ptr);
}
string &string :: operator = (const char *chrs)
{
if (this != &chrs)
{
delete [ ] ptr;
size = strlen (chrs);
ptr = new char[size + 1];
strcpy (ptr, chrs);
}
return (*this);
}
int main ( )
{
string str;
str = “Hello World”;
cout << str << endl;
return (0);
}