<thread split from here>
Could i have an elaboration on this explanation please?
My poblem being that i have wrote 2 objects to a binary file called "data.dat"
No problem there.
But then i have a function that needs to find the number of objects in the file.I can do this no problem in my main,however i cant seem to get it working with my class function.
My problem is how can my function in the class implementation file have access to the file data.dat that was created in the main.I have tried it the following way but have it does not give the correct answer.
void class::getNumberOfoBJECTS(HOW DO I PASS FILENAME HERE?) {
// This variable will store the return of tellg(),or size of the file in bytes.
int sizeOfFile = 0;
int sizeOfObject = 0;
int numOfObjects = 0;
fstream* file = new fstream("data.dat", fstream::in | fstream::binary);
// Now i am going to open file for reading and find the
// size of my file by using seekg for the file pointer
// and tellg to return the size in bytes.
// move file pointer to the eof.
file->seekg(0,fstream::end);
//use tellg() to get the size of the file.
sizeOfFile = file->tellg();
file->close();
cout << "Size of file is " << sizeOfFile << endl;
sizeOfObject = sizeof(OBJECT);
numOfObjects = sizeOfFile / sizeOfObject;
cout << "Number of objects in file is:" << numOfObjects << endl;
}