Solved

Write and read an object in binary file

Posted on 2003-10-21
6
322 Views
Last Modified: 2010-05-18
hi there
i wanna to write and read a complex data as a binary ..in and from a binary file
thanks
0
Comment
Question by:mhd-it
6 Comments
 
LVL 16

Expert Comment

by:imladris
ID: 9592827
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
 
LVL 8

Accepted Solution

by:
Exceter earned 125 total points
ID: 9594237
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
 
LVL 7

Expert Comment

by:burcarpat
ID: 9595912

  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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 16

Expert Comment

by:imladris
ID: 9616392
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
 

Author Comment

by:mhd-it
ID: 9629348
thanks for all guys ..who's help me
0
 
LVL 8

Expert Comment

by:Exceter
ID: 9629750
You are most welcome.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

919 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now