This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

stringstreams and stringbuf in gcc 3.2.x



I am using stringstreams and was trying to manipulate the contents of the stream via the associated stringbuf (via the 'sputn' method).

As far as I leared by looking at the implementation in <sstream> the stream uses a string as buffer. But if one enlarges the buffer the (implicit?) assertion that the buffer size and the string size match seems to break.

I have attached an example that produces the expected result with IRIX's CC and HP's aCC but displays a shortend version of the stream with gcc 3.2.


Peter


--

Peter Hrenka Tel. +49 (0)7071-9457-263
science + computing ag
Hagellocher Weg 71-75 mailto: P.Hrenka@science-computing.de
D-72070 Tübingen WWW: http://www.science-computing.de/

**********************************************************************
*** Events/Aktivitäten ***
*** ***
*** CeBIT 2003, Hannover ***
*** 12.-19.03.2003 ***
*** LinuxPark, Halle 6, Stand A52-265 ***
*** ***
**********************************************************************
#include <iostream>
#include <sstream>
#include <string>

int
main(int argc, char* argv[]) {

   const std::string numString("0123456789");
   std::stringstream str(numString);

   std::basic_streambuf<char>* buf=str.rdbuf();

   buf->pubseekpos(9);
   buf->sputn("abcdefghij",10);

   buf->pubseekoff(0,std::ios_base::beg);
   std::cout << "Stream: " << str.str() << "\nBuffer: " << buf << std::endl;

   buf->pubseekoff(1,std::ios_base::beg);
   std::cout << "Stream: " << str.str() << "\nBuffer: " << buf << std::endl;

   buf->pubseekoff(0,std::ios_base::beg);
   std::cout << "Stream: " << str.str() << "\nBuffer: " << buf << std::endl;

   return 0;

}

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]