c++ rdbuf()->pubsetbuf for a stream, using a char buffer. I have no data in it

Maybe can exist a better solution, but this is what I have:
1
2
3
mybuffer   = new char[265536](); // all to zero 
the_stream = new stringstream ;
the_stream->rdbuf()->pubsetbuf(mybuffer,265536);


I have a put function:

1
2
3
4
5
6
7
8
9
template <class TTput_stream>
void W_inpout::W_stream::put (TTput_stream &value) {   
   int a =  sizeof value;
   const char * buffer ;
   buffer = reinterpret_cast<const char*> (&value);
   the_stream->write(buffer,sizeof value);
   loc+= sizeof value;
   if (lof<loc)  lof=loc; 
}

And Get function:

1
2
3
4
5
6
7
8
template <class TTget_stream>
void W_inpout::W_stream::get(TTget_stream & value) {
    char * buffer ;
    buffer = reinterpret_cast< char*> (&value);
    the_stream->read(buffer, sizeof value);  
    loc=int(the_stream->tellg());
    the_stream->seekp(the_stream->tellg());
}

It works for me. If I put some values (in example one int, 2 floats, 3 doubles), I can recover them without problem (Doing a seekg before calling the get function).

But I have a problem. I want to access to 'mybuffer' data and I discover that after some 'put' commands I keep having zeros in all the 265536 positions.

for (int x=0;x<265536;x++) { if (mybuffer[x]!=0) .... )

I dont understand what is happening. Where is my data? Why does my buffer seems to be empty? Thanks
Topic archived. No new replies allowed.