reading file byLine

H. S. Teoh via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Thu Sep 3 16:30:48 PDT 2015


On Thu, Sep 03, 2015 at 11:22:09PM +0000, Namal via Digitalmars-d-learn wrote:
> >Sorry, I didn't notice the "convert all the elements in it to integer"
> >part.
> >I think I saw reference to the to! before...that is one way to convert.
> >
> >auto words = file.byLine()           // you've all lines in range
> >                   .map!(a => a.split)
> >		   .map!(a => to!int(a)).array();
> 
> 
> import std.file, std.stdio, std.string, std.conv;
> 
> void main(){
> 
> 	auto file = File("text.txt");
> 	auto numbers = file.byLine()
>                .map!(a => a.split)
>                .map!(a => to!int(a)).array();
> 	
> 	writeln(numbers);
> }
> 
> ep18.d(7): Error: no property 'map' for type 'ByLine!(char, char)'

	import std.algorithm : map;


T

-- 
Never step over a puddle, always step around it. Chances are that whatever made it is still dripping.


More information about the Digitalmars-d-learn mailing list