Friday, October 03, 2008

Hello world !

Tập tành viết blog thôi ^o^
Hello seems to be the hardest word ! (@kavax-JGuru)


#include "iostream.h"
#include "string.h"

class string {
private:
int size;
char *ptr;

public:
string() : size(0), 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);
}



:-)

1 comment:

MediocreNinja said...

ai vào đây thì comment mở hàng giùm đê :)