Thread overview | ||||||
---|---|---|---|---|---|---|
|
July 14, 2011 how to raw read a struct or value? | ||||
---|---|---|---|---|
| ||||
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? |
July 14, 2011 Re: how to raw read a struct or value? | ||||
---|---|---|---|---|
| ||||
Posted in reply to hasnoth | 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
|
July 14, 2011 Re: how to raw read a struct or value? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Graham Fawcett | 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:
>
>> 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);
In fact, you can read a struct/int this way too:
f.rawRead((&x)[0..1]);
-Steve
|
July 14, 2011 Re: how to raw read a struct or value? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Steven Schveighoffer | 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:
>
>> 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);
>
> In fact, you can read a struct/int this way too:
>
> f.rawRead((&x)[0..1]);
>
> -Steve
Aha! that makes sense. Thanks, Steve.
Graham
|
Copyright © 1999-2021 by the D Language Foundation