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

Jarrett Billingsley kb3ctd2 at yahoo.com
Thu Mar 22 21:46:47 PDT 2007


"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. 




More information about the Digitalmars-d-learn mailing list