How to count the number of objects in a file stream?
Expand Post »
I want to know that how many Student class objects in a file.
plz help me out.
Below is a class of Students and 2 function for read and write object in a file, in read function
Re: How to count the number of objects in a file stream?
This: while(in.eof()!= 1)
is probably why it is always shows the last object read in twice. You shouldn't use the return value of eof() to control performance of a loop body for that very reason. Lot's of folks have bookmarked a reference to a technical explanation for why that's so, but I've never really understood it all that well, so I won't try to explain it. I just know this type of problem can develop when you use that type of approach. To try to fix it, try this:
Re: How to count the number of objects in a file stream?
Well how have you written the records in the file from which you are taking the input ?
Extras :
>Try not using .eof() function its not good to use it like this several times discussed already in this forum.
>And within the read looping you can always include a counter right to know how much you have read.
Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.
This thread is more than three months old
No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.