Reading a string in binary mode

Christof Schardt csnews at schardt.info
Mon Mar 3 13:44:11 PST 2014


I'm evaluating D and try to write a binary io class.
I got stuck with strings:

    void rw(ref string x)
    {
        if(_isWriting)
        {
            int size = x.length;
            _f.rawWrite((&size)[0..1]);
            _f.rawWrite(x);
        }
        else
        {
            int size;
            _f.rawRead((&size)[0..1]);

            ... what now?
        }
    }

Writing is ok, but how do I read the bytes to the
string x after having its size?





More information about the Digitalmars-d-learn mailing list