Error proofing reading files with fstream

Started by
0 comments, last by vNistelrooy 19 years, 5 months ago
Hi, I'm building an IO class based on the one in the Enginuity series but using fstreams instead of the c functions (fopen etc). One thing I would like to do is add in error proofing/checking so that my class will flag up any appropriate problems. I'm trying to decide if its best to this by return types (ie return false or an error code if something goes wrong) or whether to throw an exception. Opinions? The other thing I was wondering is how to check I'm reading the correct data. I can check the length of the file matches what is expected but wondered if there was a better way. I suppose I'm looking for ideas on creating file formats and how to check a particular file i read in is formatted correctly with all the data in the right order. Any references to online articles or books etc would be appreciated. Thanks Jon
Advertisement
Quote:Original post by jonboym
The other thing I was wondering is how to check I'm reading the correct data. I can check the length of the file matches what is expected but wondered if there was a better way. I suppose I'm looking for ideas on creating file formats and how to check a particular file i read in is formatted correctly with all the data in the right order. Any references to online articles or books etc would be appreciated.

Jon


Read whatever you want 10 times, then compare all the read data, chose the data that was read most times. [rolleyes]
"C lets you shoot yourself in the foot rather easily. C++ allows you to reuse the bullet!"

This topic is closed to new replies.

Advertisement