Read Complete File to Array of Lines
sclytrack
sclytrack at iq87.fr
Fri May 11 08:10:40 PDT 2012
On 05/11/2012 05:00 PM, Paul wrote:
> I would like to read a complete file in one statement and then process
> it line by line.
>
> foreach (line; MyFile)
> etc.
>
> Is it possible to read a file into and array of lines?
> Thanks
---SOURCE
import std.stdio;
import std.file;
int main()
{
writeln("start");
foreach( line; File("src/main.d").byLine())
{
writeln(line);
}
writeln("stop");
return 0;
}
---OUTPUT
start
import std.stdio;
import std.file;
int main()
{
writeln("start");
foreach( line; File("src/main.d").byLine())
{
writeln(line);
}
writeln("stop");
return 0;
}
stop
More information about the Digitalmars-d-learn
mailing list