This is fully consistent with what the standard tells us. Here is the relevant information:
The constructor version that you used:
Creates an std :: basic_stringbuf object by calling the default constructor std :: basic_streambuf, initializes the character sequence with an empty string and sets the mode to which, followed by initialization of the associated character sequence, as if str (new_str) had been called.
The default basic_stringbuf is not interesting here, but << 21>:
Deletes the entire base character sequence of this std :: basic_stringbuf, and then sets up a new base character sequence containing a copy of the contents of s .... To add streams (mode and ios_base :: ate == true), pptr () == pbase () + s.size (), so that subsequent output will be added to the last character copied from s
Finally, tellg() , which calls pubseekoff in the buffer:
If ios_base :: in is enabled and this buffer is open for reading (i.e. if ((which and ios_base :: in) == ios_base :: in), then repositions read pointer std :: basic_streambuf :: gptr: .. then newoff - current pointer position (gptr () - eback () in this case)
To summarize: since you have not changed the position of the position in any way (the constructor only modifies the position of the position), it returns 0.
source share