Category : Files from Magazines
Archive   : CUJ9411.ZIP
Filename : STR.H

 
Output of file : STR.H contained in archive : CUJ9411.ZIP
LISTING 1 - A simple string class
// str.h

#include

class ostream;
class istream;

class string {
public:
string();
string(const char*);
~string();

friend string operator+(const string&, const string&);
string& operator+=(const string&);
friend int operator==(const string&, const string&);
friend int operator!=(const string&, const string&);
friend ostream& operator<<(ostream&, const string&);
friend istream& operator>>(istream&, string&);
char& operator[](size_t);
size_t length() const;

private:
char* data;
size_t count;
void clone(const char *);
};

inline string::string()
{
*(data = new char[1]) = '\0';
count = 0;
}

inline string::string(const char *s)
{
clone(s);
}

inline string::~string()
{
delete [] data;
}

inline int operator!=(const string& s1, const string& s2)
{
return !(s1 == s2);
}

inline char& string::operator[](size_t pos)
{
return data[pos];
}

inline size_t string::length() const
{
return count;
}


  3 Responses to “Category : Files from Magazines
Archive   : CUJ9411.ZIP
Filename : STR.H

  1. Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!

  2. This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.

  3. But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: http://www.os2museum.com/wp/mtswslnk/