Topic: epptr and egptr in std::basic_stringbuf<>::overflow()


Author: brock@ivi.fhg.de ("Christian Brock")
Date: Wed, 2 Apr 2003 18:31:51 +0000 (UTC)
Raw View
 I have two questions about the right behavior of
std::basic_stringbuf<>::overflow()

The standard says at 27.7.1.3/8:
... If ( mode & ios_base::in) != 0, the function alters the read end pointer
egptr() to
point just past the new write position (as does the write end pointer
epptr()).


FIRST (MAIN) QUESTON:
 I interpret this (and I know one major library doing the same) as:

  epptr = egptr = pptr+1;

 However this implies a call to overflow() for each written character
 causing a performance nightmare (overflow is virtual).

 Is my interpretation correct?

SECOND QUESTION:
 Given the following code

  std::stringbuf sb;
  std::iostream ss(&sb);
  ss << "13 12 11";

  int a, b;
  ss >> a >> b;
  assert(a == 13 && b == 12);

  sb.pubseekoff(0, std::ios_base::beg, std::ios_base::out);

  ss << 7; /* 1 */

  /* after this line egptr() should point to '3'? */

  int c;  /* 2 */
  ss >> c;

 - What returns gptr() and egptr() after /* 1 */?
 - What returns str() after /* 1 */?
 - What is c after /* 2 */?
   According to the std I would expect either /* 2 */ to fail or c==7 (not
11 or 73).

Thanks Chr.


---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]