This question is related to a prior question of mine. I used the code below to inspect the values in the streambuf
object associated with cout
. Using VS2010 IDE, I can see several members in this class. Could anyone point to me which one of these members points to cout's null buffer in memory ?
#include <iostream>
int main()
{
std::streambuf* p = std::cout.rdbuf();
}
Edit: Looking at the streambuf
header file one can find the following private members in the basic_streambuf
class:
_Mutex _Mylock; // thread lock
_Elem *_Gfirst; // beginning of read buffer
_Elem *_Pfirst; // beginning of write buffer
_Elem **_IGfirst; // pointer to beginning of read buffer
_Elem **_IPfirst; // pointer to beginning of write buffer
_Elem *_Gnext; // current position in read buffer
_Elem *_Pnext; // current position in write buffer
_Elem **_IGnext; // pointer to current position in read buffer
_Elem **_IPnext; // pointer to current position in write buffer
int _Gcount; // length of read buffer
int _Pcount; // length of write buffer
int *_IGcount; // pointer to length of read buffer
int *_IPcount; // pointer to length of write buffer
locale *_Plocale; // pointer to imbued locale object
I believe _Pfirst
is the address I'm looking for and it's NULL as expected.