|
-
June 24th, 2002, 08:23 AM
#1
Not getting the needed result
Iam writing into a buffer an object as bytes.
Then When Iam Trying to read from the buffer the object as say
out.write(m_pRead, BytesToRead);
where "m_pRead" is a pointer to the beginning of the buffer & "BytesToRead" is the no f bytes to read.But Iam not getting the expected result in the return file.
But when I store the same thing in a list & iterate the list to a console output, Iam getting the desired result.
so why Iam not able to get the result when Iam reading the object as bytes
Thanks in advance
-
June 24th, 2002, 01:16 PM
#2
You are writing the data in bytes so that implies that it is in binary. Have you opened the file for writing in binary?
Writing it on the console implies that it is text. Are you trying to write binary data and read it in text form? Is that what is not working?
Succinct is verbose for terse
-
June 25th, 2002, 01:27 AM
#3
the way
Iam opening the file like this: & writing to it
ofstream out("File",ios: ut);
out.write(m_pRead, BytesToRead);
out.close();
-
June 25th, 2002, 02:54 AM
#4
This depends on whether you are using fstream or fstream.h. I haven't found anything in fstream but in fstream.h, after the declaration of out, you can add
out.setmode(filebuff::binary);
Succinct is verbose for terse
-
June 26th, 2002, 01:42 AM
#5
Are you sure the object is POD (plain old data)? If the object contains pointers, the addresses of the pointers are preserved in the file. When loading, these pointers are not valid anymore.
Another problem when saving an object as binary memory block is when it has virtual methods. The VMT will also be saved. If you have RTTI enabled, the information will also be saved.
So, pointers, VMT and RTTI are not persistent. They are generated at run time and should not be stored.
Solution: try to save each member separately. Make methods for load and save and avoid to load and save the object as memory block.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|