Using TCVectorImp and TCVectorIteratorImp
I'm loading a text file using fstream. I do not want to use an array to hold the data so I chose to use a counted vector like this.
Code:
#include <cstring.h>
#include <vectimp.h>
TCVectorImp<string> Buffer;
fstream fl(filename,ios::in);
//Max line length of one line of text is 32767 characters
char *text=new char[32767];
while (!fl.eof())
{
fl.getline(text,32767);
string currentline(text);
Buffer.Add(currentline);
}
delete [] text;
TVectorIteratorImp<string> it(Buffer);
Question
Now I need to use the iterator it to iterate through the vector Buffer. How do I go about doing this? Also does not matter if each string is diff size because that is handled by the string class, not the Vector class. The Vector class just holds string objects.
I've tried some implementations and got them to compile, but did not do what I want it to.
Purpose
This function is responding to a WM_PAINT message for my window - it iterates through the current vector and writes the line of text (line by line) to the Client DC.
Benefits
This is much faster in loading and iteration than using a plain old char array.
Correct class used?
Should I use a vector for this or a list?
Vector in memory
Now is the time for all (first vector string)
good men to come to (second vector string)
the aid of their country. (third vector string)
File on disk
Now is the time for all <cr> good men to come to <cr>
the aid of their country. <cr>