Is this what you are looking for? Obviously I had help with this!!
Code:
#ifndef NEWSTRING_H
#define NEWSTRING_H
#include <list>
#include <iostream>
using namespace std;
class NewString
{
private:
list<char> m_chars;
public:
NewString() {}
NewString(const char* psz) { while (*psz != 0) { m_chars.push_back(*psz); psz++; } }
~NewString() {}
NewString& concatenate(const NewString& string2)
{ m_chars.insert(m_chars.end(), string2.m_chars.begin(), string2.m_chars.end()); return *this; }
NewString& concatenate(char c) { m_chars.push_back(c); return *this; }
const char* getText(char* buf, size_t sizBuf)
{
int i = 0;
for (list<char>::iterator it = m_chars.begin(); it != m_chars.end(); ++it)
buf[i++] =*it;
buf[i] = '\0';
return buf;
}
void display()
{
for (list<char>::iterator it = m_chars.begin(); it != m_chars.end(); ++it)
cout << *it;
}
int length() { return (int)m_chars.size(); }
bool is_substring(const NewString& string2)
{
char* pBuf = new char[m_chars.size()+1];
getText(pBuf, m_chars.size()+1) ;
char* pStr = new char[string2.m_chars.size()+1];
getText(pStr, string2.m_chars.size()+1) ;
bool ret = false;
if (strstr(pBuf, pStr) != NULL)
ret = true;
delete [] pBuf;
delete [] pStr;
}
};
#endif // NEWSTRING_H