Well, just beaten to the post

Here's another class which I think does all you've requested (it is tested!). I provide >> and << operators for cin and cout (but see below). Also I've used C library functions to save some time and trouble.
#include "stdafx.h"
#include <iostream>
using namespace std;
class str
{
char *m_pStr;
public:
str() {m_pStr = new char[1]; *m_pStr = 0;};
str(const char* pc) {m_pStr = new char[strlen(pc)+1]; strcpy(m_pStr,pc);}
~str() {delete [] m_pStr;}
bool IsEmpty() const {return strlen(m_pStr)==0;}
int Length() const {return strlen(m_pStr);}
char* Find(const char* s) const {return strstr(m_pStr,s);}
char* SubStr(const int start, const int length) const
{
if (start<0||length<1||strlen(m_pStr)<start+length) return NULL;
char* t = new char[length+1];
strncpy(t,m_pStr+start,length);
*(t+length) = 0;
return t;
};
const char* c_str() const {return m_pStr;}
friend istream& operator >> (istream& r, str& s);
};
ostream& operator << (ostream& r, const str& s) {r << s.c_str(); return r;}
/*
istream& operator >> (istream& r, str& s)
{
delete [] s.m_pStr;
char t[100];
r >> t;
s.m_pStr = new char[strlen(t)+1];
strcpy(s.m_pStr,t);
return r;
}
*/
int main(int argc, char* argv[])
{
str s1;
str s2("Some data"

;
const str cs("Help!"

;
cout << (s1.IsEmpty() ? "s1 empty" : "s1 not empty"

<< endl;
cout << (s2.IsEmpty() ? "s2 empty" : "s2 not empty"

<< endl;
cout << "s1 length=" << s1.Length() << endl;
cout << "s2 length=" << s2.Length() << endl;
cout << "start of \"data\" in s2=" << (s2.Find("data"

- s2.c_str()) << endl;
cout << (s2.SubStr(0,0)==NULL) << endl; // Error NULL, result 1
cout << (s2.SubStr(s2.Length(),0)==NULL) << endl; // Error NULL, result 1
cout << (s2.SubStr(s2.Length()+1,0)==NULL) << endl; // Error NULL, result 1
cout << (s2.SubStr(-1,0)==NULL) << endl; // Error NULL, result 1
cout << ">" << s2.SubStr(3,3) << "<" << endl; // "e d" hopefully
cout << s2 << "hey!" << s2 << s2 << "there!" << endl;
// char pc[100];;
// cin >> s2 >> pc;
// cout << ">" << s2 << "<" << pc << endl;
return 0;
}
Unfortunately there's few bugs in the VC++ 6 compiler that prevent the istream (cin) function and the calls from compiling. This is all fixed in VC++ 7 (.Net beta2).
Firstly the friend declaration is not recognised correctly, causing the m_pStr member to be inaccessible. Simplest solution would be to declare it public as a workaround. Secondly the compiler considers the ">>" operator in
cin >> s2 >> pc;
to be ambiguous. I'm not sure how to get round this one. Frankly I've forgotten what sp level I have on my machine here at home; maybe it all works with sp5. You can uncomment the code and try it out.
I added the c_str() class function (just like <string>) so I could get the offset of the Find() result, although it's a useful function to have anyway.

Hope that this helped!
