On Monday, 27 February 2012 at 18:56:15 UTC, Justin Whear wrote:
On Mon, 27 Feb 2012 19:42:36 +0100, Tobias Brandt wrote:

Doesn't the struct alignment play a role here?

Good point. If the data is packed, you can toss an align(1) on the front
of the struct declaration.

So, something like this should work:

import std.stdio : writeln, writefln;
import std.stream;

align(1) struct TaqIdx {
  char[10] symbol;
  int tdate;
  int begrec;
  int endrec;
}

void main() {
  auto input = new File("T200808A.IDX");
  TaqIdx taq;

  input.readExact(&taq, TaqIdx.sizeof);
writefln("%s %s %s %s", taq.symbol, taq.tdate, taq.begrec, taq.endrec);
}

Thanks so much!

TJB

Reply via email to