#include <iostream.h>
#include <string.h>
class string
{
private:
int size;
char *ptr;
string() : size(0), ptr(new char[1]) { ptr[0] = 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);
}
>>61384840
I fail to see how this is relation to mens fashion or youtubers, which is what this board is for.
>>61384840
what computer language is this?
i prefer times new roman
>>61384897
It's sepples
>>61384840
>if (this != &chrs)
This condition will never be false. You obviously know nothing about pointers.
>>61384840
> uses <iostream.h> over <stdio.h>
> uses endl instead of "\n"
Off yourself
>>61384840
Dumb C++ poster
>C++
Quick, bleach my eyes!