More binary I/O problems
Basile B. via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Fri Apr 8 19:42:19 PDT 2016
On Friday, 8 April 2016 at 20:58:06 UTC, Charles Hixson wrote:
>>[...]
> And that worked, but suddenly (after a compiler upgrade, did
> that matter? I'd also changed the program, though in ways that
> shouldn't have affected this.) it stopped working with the
> message:
> let4a.d(138): Error: no [] operator overload for type Chnk
>
> [...]
you can cast too (void*)
struct Chnk
{
char[20] wrd;
ubyte length;
ulong id;
this (ulong id, string wrd) {}
uint hCode () {return 0;}
string toString () { return "";}
string wrdStr() {return "";}
}
void main()
{
import std.file: read, write;
Chnk c;
write("a.txt", (cast(void*)&c)[0..Chnk.sizeof]);
auto buff = read("a.txt", Chnk.sizeof);
(cast(void*)&c)[0..Chnk.sizeof] = buff[0..Chnk.sizeof];
}
More information about the Digitalmars-d-learn
mailing list