M
Mike Wahler
Maya said:Apart from being a pointer, what would be the benefit of using
'std::filebuf'
'std::filebuf' is not a pointer. It's a user (the 'user'
here being the standard library) defined type.
than using the std::fstream?
'std::fstream' is a (derived) stream class.
'std::filebuf' is a (derived) stream buffer class.
They're not the same thing. 'filebuf' is the implementation
of an 'fstream's transport layer.
As far as I can see, I would use the same methods in 'filebuf' that I
would when using std::fstream.
No.
Thus my question, what do I gain by using
'std::filebuf' instead of std::fstream?
Confusion.
If you want to do file i/o in C++, use the 'fstream',
'ifstream' and/or 'ofstream' classes.
Stream buffer classes can be derived from in order to
create custom i/o handling (often to handle a new type
of device), but this is considered by many to be a more
'advanced' usage of iostreams, not really suitable for
the beginner to work with (but go ahead if you're feeling
adventurous. The book I cite below should help greatly.
with that).
A very good explanation of C++ IOStreams, stream buffers,
and how they're designed and work can be found in the
excellent book:
http://www.langer.camelot.de/iostreams.htm
-Mike