digitalmars.D.learn - how to raw read a struct or value?
- hasnoth (5/5) Jul 14 2011 auto file = io.File("test.txt", "rb");
- Graham Fawcett (8/14) Jul 14 2011 The same method:
-
Steven Schveighoffer
(6/19)
Jul 14 2011
On Thu, 14 Jul 2011 09:36:47 -0400, Graham Fawcett
... - Graham Fawcett (3/30) Jul 14 2011 Aha! that makes sense. Thanks, Steve.
auto file = io.File("test.txt", "rb"); auto fp = file.getFP(); int x; io.fread(&x, x.sizeof, 1, fp); what's the “d method” to do that?
Jul 14 2011
On Thu, 14 Jul 2011 09:01:29 +0000, hasnoth wrote:auto file = io.File("test.txt", "rb"); auto fp = file.getFP(); int x; io.fread(&x, x.sizeof, 1, fp); what's the “d method” to do that?The same method: import core.stdc.stdio : fread; fread(&x, x.sizeof, 1, fp); or, if you are using an array, you can use File.rawRead: int[10] xx; f.rawRead(xx); Graham
Jul 14 2011
On Thu, 14 Jul 2011 09:36:47 -0400, Graham Fawcett <fawcett uwindsor.ca>= = wrote:On Thu, 14 Jul 2011 09:01:29 +0000, hasnoth wrote:In fact, you can read a struct/int this way too: f.rawRead((&x)[0..1]); -Steveauto file =3D io.File("test.txt", "rb"); auto fp =3D file.getFP(); int x; io.fread(&x, x.sizeof, 1, fp); what's the =C2=93d method=C2=94 to do that?The same method: import core.stdc.stdio : fread; fread(&x, x.sizeof, 1, fp); or, if you are using an array, you can use File.rawRead: int[10] xx; f.rawRead(xx);
Jul 14 2011
On Thu, 14 Jul 2011 13:05:33 -0400, Steven Schveighoffer wrote:On Thu, 14 Jul 2011 09:36:47 -0400, Graham Fawcett <fawcett uwindsor.ca> wrote:Aha! that makes sense. Thanks, Steve. GrahamOn Thu, 14 Jul 2011 09:01:29 +0000, hasnoth wrote:In fact, you can read a struct/int this way too: f.rawRead((&x)[0..1]); -Steveauto file = io.File("test.txt", "rb"); auto fp = file.getFP(); int x; io.fread(&x, x.sizeof, 1, fp); what's the “d method” to do that?The same method: import core.stdc.stdio : fread; fread(&x, x.sizeof, 1, fp); or, if you are using an array, you can use File.rawRead: int[10] xx; f.rawRead(xx);
Jul 14 2011