Hello,
This is for an assignment I have to do, I have completed most of it just can't get one part to work correctly.
The assignment is:
The TextFieldLoader class will have only one constructor and MUST accept the following parameters only:
1. filename (const char *) that will be used to read (and store) the entire contents of the file into memory.
2. row (int), and
3. column (int) representing where on the screen the TextFieldLoader is located.
4. width (int), and
5. height (int) representing the TextFieldLoader's dimensions.
Once instantiated, the TextFieldLoader must use the functions seekg( ) and tellg( ) to dynamically determine how large the file is before loading the contents of the file into memory using only one call to the read( ) function.
Now I have completed most of whats required except that I am not sure how to proceed with dynamically allocating memory for the file input and the using the read function.
This is what I have done:
//declaration
class TextFieldLoader: public ifstream, public TextField{
public:
TextFieldLoader(/*const*/ char*, int, int, int, int);
~TextFieldLoader();
};
//definition
TextFieldLoader::TextFieldLoader(/*const */char *fn, int row, int col, int width, int height)
: ifstream(fn), TextField(fn, row, col, width, height){
int length;
//determining the size of the file
//move to end of file
seekg(0, ios::end);
length = tellg();
seekg(0, ios::beg);
//read into memory
read(fn, length);
}
I think I have got the memory allocation correct but can't get the read to work properly.
Thanks.