How can i set a new char array to be the buffer of a fstream's filebuf, there is a function (setbuf) in the filebuf but it is protected. while searching on the web, some sites mention fstream::setbuf but it doesn't seem to exist anymore.
Thanks
How can i set a new char array to be the buffer of a fstream's filebuf, there is a function (setbuf) in the filebuf but it is protected. while searching on the web, some sites mention fstream::setbuf but it doesn't seem to exist anymore.
Thanks
The point of a protected member function is that it is meant to be overridden by your derived subclass. Here is a short section of the libstdc++ manual which discusses exactly that.
Here's an excerpt from <streambuf>
which makes the same point in code:
// [27.5.2.4.2] buffer management and positioning
/**
* @brief Manipulates the buffer.
*
* Each derived class provides its own appropriate behavior. See
* the next-to-last paragraph of
* http://gcc.gnu.org/onlinedocs/libstdc++/manual/bk01pt11ch25s02.html
* for more on this function.
*
* @note Base class version does nothing, returns @c this.
*/
virtual basic_streambuf<char_type,_Traits>*
setbuf(char_type*, streamsize)
{ return this; }
streambuf is designed to be customized using the template method pattern, where the public methods are not virtual, and subclasses customize the behavior by implementing non-public virtual methods.
In the case at hand, the public method which calls setbuf is named pubsetbuf.
Note however that basic_filebuf's implementation of setbuf is rather loosely specified: The only guarantee is that setbuf(0, 0) makes the stream unbuffered. In other cases, the effect is implementation-defined.