Thread: stream object

  1. #1
    Registered User
    Join Date
    Jan 2009

    stream object

    Hello, rather new to C++, but I need a solution to stream an object in C++.
    I tried the following code, and wanted to store the object dt in memory buffer, and read it back into newdt.
    But nothing changed in the newdt.
    Wat did I do wrong?
    class DataClass : public TStreamableBase {
        int a;
        int b;
        DECLARE_STREAMABLE(  , DataClass,1);
    void* DataClass::Streamer::Read(ipstream& in, uint32) const
      ReadBaseObject(static_cast<DataClass*>(GetObject()), in);
      in >> GetObject()->a >> GetObject()->b;
      return GetObject();
    void DataClass::Streamer::Write(opstream& out) const
      	WriteBaseObject(static_cast<DataClass*>(GetObject()), out);
    	out << GetObject()->a << GetObject()->b;
    void main(){
        //FILE *fp;
        char * buffer[100];
        int stop;
        DataClass dt;
        DataClass newdt;
        printf(" Initial Contence of the buffer newtd is: %d, %d \n",newdt.a,newdt.b);
        streambuf bf((char *)(&newdt), sizeof(DataClass));
        ptbf = &bf;
        opstream outpstr(ptbf);
        ipstream inpstr(ptbf);
        ModuleId mid = GetModuleId();
        outpstr.writeObject(&dt, 1,  mid);
        inpstr.readBytes(&newdt, sizeof(DataClass));
        printf(" Contence of the buffer newtd is: %d, %d \n",newdt.a,newdt.b);

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    You might want to give more context since you are using components that do not come from the standard library. For example, what library/framework are you using?
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Jan 2009
    I use Borland C++ 5, under Windows (want to switch to old DOS, 80186 code) and used object stream objstrm.h...if that's what you asked me...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Texture Management in OpenGL
    By Brafil in forum Game Programming
    Replies: 13
    Last Post: 07-16-2009, 04:32 PM
  2. std::string object is overwritten in output stream
    By eatwithaspork in forum C++ Programming
    Replies: 1
    Last Post: 04-08-2009, 03:20 PM
  3. Question on l-values.
    By Hulag in forum C++ Programming
    Replies: 6
    Last Post: 10-13-2005, 04:33 PM
  4. Set Classes
    By Nicknameguy in forum C++ Programming
    Replies: 13
    Last Post: 10-31-2002, 02:56 PM
  5. Set Classes
    By Nicknameguy in forum C++ Programming
    Replies: 3
    Last Post: 10-21-2002, 07:40 PM