reading file byLine

Namal via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Thu Sep 3 16:22:09 PDT 2015


> 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)'




More information about the Digitalmars-d-learn mailing list