Topic: clearing a strstreambuf?
Author: "Steve Thomas" <sthomas@wisewire.com>
Date: 1997/11/13 Raw View
I would appreciate the help of any iostream gurus
I derived a class from strstreambuf to implement some custom functionality,
but had some difficulty in finding a way to clear, or empty, the buffer.
Finally, I stumbled upon the following method, which works, but which I'm
not sure is the best, most efficient, or most reliable:
int derived_streambuf::clear()
{
int nRet = 0; // return value initialized to a good value (not EOF)
int nSize = blen();
// clear out the buffer contents
memset( base(), 0, nSize );
// set the base, get, and put pointers
setb( base(), base(), 0 );
setg( 0, 0, 0 );
setp( 0, 0 );
return nRet;
}
This clear method is called at the end of sync(), when the stream is
flushed.
What are the effects of setting my pointers again in this manner?
Thanks so much.
Steve
---
[ comp.std.c++ is moderated. To submit articles: try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ FAQ: http://reality.sgi.com/employees/austern_mti/std-c++/faq.html ]
[ Policy: http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu ]