Reading bytes and converting to int

Jonathan M Davis jmdavisProg at gmx.com
Sat Aug 25 13:58:35 PDT 2012


On Saturday, August 25, 2012 22:49:18 joao wrote:
> Ok, so I tried both ways and gave errors:
> import std.stdio, std.cstream, std.system, std.bitmanip;
> 
> File f = File("filename");
> auto buf = f.rawRead(new ubyte[4]);
> auto i = peek!(uint, Endian.littleEndian)(buf);
> 
> std.stdio.File conflicts with std.stream.File

Then either don't import both or use the full import.

auto file = std.stdio.File("filename");

But I wouldn't advise using std.stream for anything unless you have to. As the 
note in its documentation states, it's considered out-of-date and will be 
replaced.

> and
> 
> auto file = File("filename");
> auto buffer = ubyte[](4);
> buffer = file.rawRead(buffer);
> auto i = peek!(uint, Endian.littleEndian)(buffer);
> 
> found '[' when expecting '.' following ubyte and ']' when
> expecting identifier following 'ubyte'

It's missing new. My mistake.

auto buffer = new ubyte[](4);

or as David pointed out, you get just allocate the array in the rawRead call:

auto buf = file.rawRead(new ubyte[](4));

- Jonathan M Davis


More information about the Digitalmars-d-learn mailing list