Here's the code.
Code:
#include <cstring.h>
#include <classlib\vectimp.h>
class TString
{
public:
TString() {};
TString(const string &s):myString(s) {};
TString(const TString &sc):myString(sc.myString) {};
TString& operator=(const TString &sc)
{myString=sc.myString;return *this;};
int operator==(const TString &sc) const
{return myString==sc.myString;};
int operator<(const TString &sc) const
{return myString<sc.myString;};
private:
string myString;
};
typedef TCVectorImp<TString> TStringContainer;
typedef TCVectorIteratorImp<TString> TStringIterator;
class TEditWindow:public TMDIChild
{
TClientDC *CDC;
TFont Font;
TEXTMETRIC FontMetrics;
int numstrings;
TStringContainer Buffer;
public:
TEditWindow(TMDIClient& parent, const char far* title = 0,
TWindow* clientWnd = 0, bool shrinkToClient = false,
TModule* module = 0);
virtual void SetupWindow(void);
bool EvEraseBkgnd( HDC ) {return TRUE;};
virtual void Paint(TDC &dc,bool erase,TRect &rect);
};
TEditWindow::TEditWindow(TMDIClient& parent,
const char far* title,
TWindow* clientWnd,
bool shrinkToClient,
TModule* module):
TMDIChild(parent,title,
clientWnd, shrinkToClient,module)
{
Attr.Style|=WS_VSCROLL|WS_HSCROLL;
fstream fl(title,ios::in);
char text[256];
do
{
fl.getline(text,256);
Buffer.Add(TString(text));
} while (!fl.eof());
}
void TEditWindow::SetupWindow(void)
{
CDC=new TClientDC(HWindow);
CDC->GetTextMetrics(FontMetrics);
CreateCaret(false,1,FontMetrics.tmHeight);
SetCaretPos(0,0);
ShowCaret();
}
void TEditWindow::Paint(TDC &dc,bool erase,TRect &rect)
{
TStringIterator it(Buffer);
while (it)
{
//Iterate through vector of strings and output to window here
}
}
For some reason this code does not add TString objects to the Vector of TString objects. If I retrieve the count, it is always 0. I've typedef'ed TCVectorImp and TCVectorIteratorImp to TStringContainer and TStringIterator respectively.
Please ignore all of the Windows relevant code (and 3rd party library code which encapsulates Windows API) and just help me with the STL classes.
Why doesn't this add TString objects to the vector??