Converting from std.file.read's void[]
Jonathan M Davis
jmdavisProg at gmx.com
Tue Sep 21 18:03:07 PDT 2010
On Tuesday, September 21, 2010 17:34:26 bearophile wrote:
> > Take a look at the rawWrite/rawRead methods of std.stdio.File.
>
> I have just tried those a little. Python file object doesn't have a eof()
> method. This D2 program shows that eof() is false even when the whole file
> has being read, is this correct?
>
>
> import std.stdio: File;
> void main() {
> double[3] data = [0.5, 1.5, 2.5];
> auto f = File("test.raw", "wb");
> f.rawWrite(data);
> f.close();
> f = File("test.raw", "rb");
> assert(!f.eof());
> f.rawRead(data);
> assert(f.eof()); // Assertion failure
> }
>
> Bye,
> bearophile
I believe that the typical behaviour in C and C++ is that eof() is false until
you've tried to read beyond the end of the file. So, you get one more read than
you might expect. You do the read, an then check eof() rather than checking
eof() and then doing the read if it isn't true.
- Jonathan M Davis
More information about the Digitalmars-d-learn
mailing list