I am writing an iOS app which uses a piece of c++ code which is reading pieces of data from a file using istream. The code works but its used repeatedly and it eventually hits a limit of reads and then something goes wrong. It appears to read in successfully but gcount returns 0. This is not specific to a certain file or case because after the app is restarted everything will pick up from where it left off and fail once the limit is hit again. It feels like there is some istream session that gets into a bad state that I can't get out of. I am closing the files I open.
This is how I open the streams
iFiles.push_back(new ifstream([[[arrayOfPaths objectAtIndex:i] absoluteString] cStringUsingEncoding:NSASCIIStringEncoding] , ios::in | ios::binary));
Then I have a loop where I read in pieces of this file:
while (!iStreams[0]->eof())
{
vector<vector<int64_t> > matrix;
int length = 0;
for (int i = 0; i < rows; i++)
{
char * buffer = new char [DEMUX_BUFFER];
iStreams[i]->read(buffer, DEMUX_BUFFER);
int int64Groups;
if(iStreams[i]->gcount() == 0)
{
//this is the catch for the bad case but buffer contains something even though count is 0
}
.....
This is a hard question to ask so please let me know if you need more information. I am hopping someone out there has had a similar issue.
Thank you