TITLE: How to rewind a ostrstream after calling str()? PROBLEM: jlieb@is.morgan.com (Jerry Liebelson), 17 Jul 93 What is the proper way to rewind the buffer in an ostrstream after the str() method is invoked? For example, ostrstream buf; buf << "STRING 1"; const char *sPtr = buf.str(); ... delete sPtr; // ??? buf << "STRING 2"; RESPONSE: vinoski@apollo.hp.com (Steve Vinoski), Hewlett-Packard Corporation Replace the delete call with a call to unfreeze the strstreambuf, then seek: ostrstream buf; buf << "String 1" << ends; const char *sPtr = buf.str(); // ... buf.clear(); // freezing may have set error state buf.rdbuf()->freeze(0); // unfreeze; buf now owns the char* again buf.rdbuf()->seekoff(0, ios::beg, ios::out); buf << "String 2"; // etc. See the following brand new book for (many) more details: Steve Teale C++ IOStreams Handbook Addison-Wesley ISBN 0-201-59641-5