eliminate cast
Dee Girl
deegirl at noreply.com
Wed May 14 10:03:30 PDT 2008
BCS Wrote:
> Reply to Dee,
>
> > There is a file data.txt with numbers:
> >
> > 345
> > 5467
> > 45
> > 238
> > ...
> > And I want to load into an array of uint like this.
> >
> > auto sizes = map!
> > (to!(uint, string))
> > (compose!(split, q{cast(string) std.file.read(a)})("data.txt"));
> >
> > It works but cast is always bad ^_^. How can I eliminate cast? Is
> > there function to read entire text file in string? Thank you, Dee Girl
> >
>
> IMHO in this case the cast is /not/ bad. It is an explicit documentation
> of your intent. The file.read function knows nothing about what it is reading
> and therefor returns ubyte[] to say "this is data" and the cast is the programer
> saying "I known this is text".
O.K. but let say we want to check for invalid file (binary and not ascii). How can I do it? Thank you, Dee Girl
More information about the Digitalmars-d
mailing list