Although an application program interacts mostly with ifstream, ofstream or fstream objects, these object connect to the file system and strings via streambuf objects. More information about the streambuf class can be found at http://www.cplusplus.com/ref/iostream/streambuf/.
A streambuf object handles the actual interaction with a file system or string (depending on which stream is used). The streambuf class is an abstract class, and it defines many abstract methods. These methods are implemented by storage specific subclasses. filebuf is a specialization that handles file operations, while stringbuf is a specialization that handles string operations.
The ios class includes a pair of rdbuf methods to get or set the streambuf object of a stream.
Note that the specialization of fstream, ifstream and ofstream is to add the methods open, close and is_open. However, these methods translate to calls to the corresponding methods of a filebuf. In other words, the file specific classes, fstream, ifstream and ofstream merely expose the extra capabilities of a filebuf (compared to a streambuf) at the stream level.
This also means that internally, a fstream ifstream or ofstream object requires a pointer to a filebuf object, and not just a streambuf object. By comparison, the ios class only needs a pointer to a streambuf object because it is more general.
The same applies to stringstream, istringstream and ostringstream. These classes include a pointer to a stringbuf object, as opposed to a pointer to a streambuf object. stringbuf is a subclass of streambuf that implements all the abstract methods. However, the stringbuf class also adds a new method to associate with a string. This is why we need to derive [i|o]stringstream from the general classes so that the method can be exposed by the str method.