Hi
I need help with reading a struct record and output it's position within the file.
The struct looks like this:
i am taking input from a binary file which is successful.
then i am reading in the record which is passed by reference.
The part that i am having trouble with is when i am trying to read the record as a whole and output it's position within the file, i keep getting memory leaks.
an example record would look like:
joe blow
123
2500.00
CODE
struct Record
{
char name;
int SIN;
double income;
};
bool submission_search(Record& r, fstream& bin_infile)
{
bool good_read;
if (good_read)
{
bin_infile.read(reinterpret_cast<char *>(&r), sizeof(Record));
streampos submission = bin_infile.tellg();
cout << endl;
cout << "submission # " << submission << ':' << ' ' << "name= " << r.name << ',' << ' ' << "SIN= " << r.SIN << ' ' << "income=$ " << r.income << ' ';
cout << endl;
}
else
{
good_read = false;
cout << "There is no record containing that submission number.\n";
}
return good_read;
}
I am confused as to how to properly use the bin_infile.tellg().
I know that it would save the current position but it doesn't seem to hold it.
Also, do i need to check for eof before i attempt a read?
This post has been edited by rizwans: 2 Feb, 2008 - 02:46 PM