I
IlyaK
Hello:
I have this simple code that needs to get a chunk of a large log file
that is being written into. At some point it stores the current
location returned from
streampos start = istream::tellg();
method.
Later on the code has to read from the stream a buffer from the start
till the end. The code is approximately like this:
streampos start = my_stream.tellg();
... // do some stuff with logging
streampos end = my_stream.tellg();
const streamsize size_to_read = (end - start);
char *buf = new char[size_to_read];
lock (m_logReadLock);
{
my_stream.flush();
my_stream.seekg(start);
my_stream.read(buf, size_to_read);
size_read = my_stream->gcount();
}
unlock (m_logReadLock);
The effect that I'm observing is that **size_read** is *smaller* than
**size_to_read** and the stream has its eof flag set. Shouldn't the
end pointer specify exactly where the stream ends and read() method
return that exact amount of data?
It is fine, I can work round it by checking the eof flag.
However, can anyone provide the explanation for this effect?
Thanks.
I have this simple code that needs to get a chunk of a large log file
that is being written into. At some point it stores the current
location returned from
streampos start = istream::tellg();
method.
Later on the code has to read from the stream a buffer from the start
till the end. The code is approximately like this:
streampos start = my_stream.tellg();
... // do some stuff with logging
streampos end = my_stream.tellg();
const streamsize size_to_read = (end - start);
char *buf = new char[size_to_read];
lock (m_logReadLock);
{
my_stream.flush();
my_stream.seekg(start);
my_stream.read(buf, size_to_read);
size_read = my_stream->gcount();
}
unlock (m_logReadLock);
The effect that I'm observing is that **size_read** is *smaller* than
**size_to_read** and the stream has its eof flag set. Shouldn't the
end pointer specify exactly where the stream ends and read() method
return that exact amount of data?
It is fine, I can work round it by checking the eof flag.
However, can anyone provide the explanation for this effect?
Thanks.