How to read a C++ class from file into memory

David Finlayson david.p.finlayson at gmail.com
Thu Mar 22 22:05:10 PDT 2007


Jarrett Billingsley Wrote:

> "David Finlayson" <david.p.finlayson at gmail.com> wrote in message 
> news:etvlr7$1a9p$1 at digitalmars.com...
> 
> > Thanks for answering my post. Do you know how I might use std.stream to 
> > read these files?
> 
> If you exactly how the data is structured, you may be able to define several 
> structures which define the layout of the data, e.g.
> 
> align(1) struct Header
> {
>     uint magic;
>     uint version;
>     char[100] comments;
> }
> 
> Or something along those lines, and then read it in with readExact:
> 
> Stream s = ...
> Header h;
> s.readExact(&h, Header.sizeof);
> 
> If the format is more complex, it'll probably take a bit more work, but 
> that's the general idea. 
> 

OK, this is what I want. Question:

Header h creates a structure of type Header. Is h a pointer? It looks like you dereferenced it with &h in readExact(). I really don't understand how D uses pointers yet.

> 



More information about the Digitalmars-d-learn mailing list