From http://www.cplusplus.com/reference/ios/ios/rdbuf/:
Some derived stream classes (such as stringstream and fstream) maintain their own internal stream buffer, to which they are associated on construction. Calling this function to change the associated stream buffer shall have no effect on that internal stream buffer: the stream will have an associated stream buffer which is different from its internal stream buffer (although input/output operations on streams always use the associated stream buffer, as returned by this member function).
And on http://www.cplusplus.com/reference/fstream/ifstream/rdbuf/:
Returns a pointer to the internal filebuf object.
Notice however, that this is not necessarily the same as the currently associated stream buffer (returned by ios::rdbuf).
So what is the internal buffer for if it's not used for input and output operations? And if it means that these two lines could return two different objects, why could this be useful?
std::stringstream ss;
ss.rdbuf(); // (1) returns "internal" stream buffer?
static_cast<std::ios&>(ss).rdbuf(); // (2) returns "associated" stream buffer?
ifstream::rdbuf()
returns not the buffer that the object currently uses? – Periscopeios::rdbuf
is for. – Tremayne