Re: Writing binary data in managed C++
From: Lord2702 (Lord2702_at_MSN.com)
Date: 10/02/04
- Next message: Epetruk: "Catching standard library exceptions in managed code (2nd post)"
- Previous message: Doug Harrison [MVP]: "Re: Size of int (once again, sorry)"
- In reply to: Peter Steele: "Writing binary data in managed C++"
- Messages sorted by: [ date ] [ thread ]
Date: Sat, 2 Oct 2004 15:08:43 -0700
You can write your struct in BinaryFormat. But if you expect it should write
as you use to write in Native C or C++ with fopen(), and fwrite(), or
open(), and write(), functions then you can not. But you can use
BinaryWriter class, it has many overloaded methods of write, which can write
your struct. Make two methods in your struct Read and Write, or Load and
Save as per your choice, and write all the types with by passing
BinaryWriter instance to these methods. This will not write any headers by
the way. for example. string: S"ABCDE", will write 05, 41, 42, 43, 44, 45
(all in hex code) in Bytes. first byte is the length of your string. Int32
will write four bytes.
Good Luck.
"Peter Steele" <psteele@z-force.com> wrote in message
news:OvgAPS0pEHA.1688@TK2MSFTNGP10.phx.gbl...
> I have a managed C++ project that contains a simple structure:
>
> struct
> {
> <multiple members>
> } mydata;
>
> I want to write the contents of this structure out to disk retaining the
> exactly binary data without any additional header information, and of
course
> be able to later read it back in. What's the best way to accomplish this?
>
>
- Next message: Epetruk: "Catching standard library exceptions in managed code (2nd post)"
- Previous message: Doug Harrison [MVP]: "Re: Size of int (once again, sorry)"
- In reply to: Peter Steele: "Writing binary data in managed C++"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|