Re: Need more examples ...
"Bertrand LUPART - Linkeo.com" <[email protected]>
| Newsgroups | gmane.comp.lang.pike.user |
|---|---|
| Message-ID | <[email protected]> |
>
> We could for sure be better at providing examples and tutorials. One of these days...
>
> There are many ways to read a file:
>
> The whole file in one sweep:
>
> string s = Stdio.read_file("file.ext");
>
> And I guess this one way of using the File object.
>
> Stdio.File f = Stdio.File("file.ext", "r");
>
> or alternatively
>
> Stdion.File f = Stdio.File();
> f->open("file.ext", "r");
>
> and then
>
> string a = f->read(1024); -> read one kb
> string b = f->read(); -> read to end of file or stream
>
>
> Hope this works.
How to read a file one line at a time :
object file = Stdio.FILE("example.txt","r");
foreach(file; int line_num; string line_data)
{
write("%O %O\n", line_num, line_data);
}
--
Bertrand