cplusplus
.com
TUTORIALS
REFERENCE
ARTICLES
FORUM
C++
Tutorials
Reference
Articles
Forum
Forum
Beginners
Windows Programming
UNIX/Linux Programming
General C++ Programming
Lounge
Jobs
Forum
General C++ Programming
Stream iterators and buffers?
Stream iterators and buffers?
Feb 6, 2013 at 3:54pm UTC
Catfish3
(666)
Do stream iterators, such as
std::istreambuf_iterator<char>
, read a chunk of bytes internally, or do they read the stream one byte at a time?
Because I am thinking to write a
BufferedFile
class which uses an
std::vector<char>
.
(If you have a better idea, go ahead.)
Last edited on
Feb 6, 2013 at 3:54pm UTC
Feb 6, 2013 at 4:51pm UTC
Cubbi
(4774)
The iterators read from the stream's in-memory buffer one byte at a time.
Feb 6, 2013 at 5:42pm UTC
Catfish3
(666)
Just to be clear: at the moment when the iterator reads a byte, it reads it from a chunk of the file, which is in memory acting as a buffer?
Thanks.
Feb 6, 2013 at 6:10pm UTC
Cubbi
(4774)
The moment the iterator reads a byte, it advances a pointer in the associated streambuf object to point to the next byte in the buffer. If the pointer reaches the end of the buffer, streambuf::underflow() reads up another chunk from the file.
Topic archived. No new replies allowed.