ifstream.read fails mysteriously

S

Sergei Shelukhin

Hi. I have the following problem; VC++ project, there's this code
operation on 500Mb file via ifstream, POS_TYPE for this case is
unsigned int which is 32-bit long.

//dataFile.good() returns 1 here. File is open in binary mode
dataFile.seekg(someValue, ios::beg); // someValue is ~247M
//dataFile.tellg() gives someValue correctly here.
POS_TYPE* dataBuffer = new POS_TYPE[someValue2]; //someValue2 is ~4k
dataFile.read((char*)dataBuffer, someValue2 * sizeof(POS_TYPE));
//at this point, gcount returns 138, bad() gives 0, and eof() and
fail() both return 1.

The interesting thing is that the error is persistent (at least for an
hour while I was debugging this) and occurs at specific locations,
while on others, including the locations closer to the end of file, it
doesn't occur.
I tried copying the file back and forth and it seems to be ok (e.g.
not bad sectors or anything).

What can be causing it? Is there any way to get a more detailed error
message?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,016
Latest member
TatianaCha

Latest Threads

Top