Write and read an object in binary file

hi there
i wanna to write and read a complex data as a binary ..in and from a binary file
thanks
mhd-itAsked:
Who is Participating?
 
ExceterConnect With a Mentor Commented:
You can write an object to file by saying,

out.write( (char*)&myobject, sizeof(myobject) );

where out is an instance of ofstream.

Cheers!
Exceter
0
 
imladrisCommented:
You can write an integer to a file by opening an output file stream, and then writing the integer to it. Something like:

#include <fstream>

ofstream fout;

int i=233;
fout.open("data");
fout<<i;
fout.close();

Reading it back in is the analogous process with an file input stream.
0
 
burcarpatCommented:

  http://www.parashift.com/c++-faq-lite/serialization.html

will give you a head start.  also check out serialization12.zip under

    http://groups.yahoo.com/group/boost/files/

-- ba
0
Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

 
imladrisCommented:
Did any of those responses help?

If any did, you should select the response(s) that helped you, and grade it (them).

If not, perhaps a clarifying question would help.
0
 
mhd-itAuthor Commented:
thanks for all guys ..who's help me
0
 
ExceterCommented:
You are most welcome.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.