Thread overview |
---|
April 10, 2015 Error of binary reading on dmd 2.067.0 | ||||
---|---|---|---|---|
| ||||
I wish to read bytes from a file using the formatted input, but it leads to a mistake - std.utf.UTFException@std\stdio.d(2719): Invalid UTF-8 sequence. // only for dmd 2.067.0 import std.stdio; int main (string[] args) { auto nf = "TestFile.txt"; // I write down a verifying file string s = [65, 225, 67]; File(nf, "w").write(s); // I try to read a file on bytes File f1 = File(nf, "r"); ubyte c; while(true) { f1.readf("%d", &c); if(f1.eof) break; writeln(c, " "); } return 0; } |
April 10, 2015 Re: Error of binary reading on dmd 2.067.0 | ||||
---|---|---|---|---|
| ||||
Posted in reply to MGW Attachments: | On Fri, 10 Apr 2015 12:15:58 +0000, MGW wrote: > I wish to read bytes from a file using the formatted input, but it leads > to a mistake - std.utf.UTFException@std\stdio.d(2719): > Invalid UTF-8 sequence. > > // only for dmd 2.067.0 import std.stdio; > > int main (string[] args) { > auto nf = "TestFile.txt"; > // I write down a verifying file string s = [65, 225, 67]; File (nf, > "w").write(s); > > // I try to read a file on bytes File f1 = File(nf, "r"); > ubyte c; > while(true) { > f1.readf("%d", &c); if(f1.eof) break; > writeln(c, " "); > } > return 0; > } are you insisting on using formatted read? it expects valid UTF-8. but you can do this instead: ubyte[1] c; while (f1.rawRead(c[]).length) { writeln(c, " "); } |
Copyright © 1999-2021 by the D Language Foundation