Solved

Write and read an object in binary file

Posted on 2003-10-21
6
321 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
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

708 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

13 Experts available now in Live!

Get 1:1 Help Now