phobos: What type to use instead of File when doing I/O on streams?

J.Frank via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sun Nov 8 14:38:51 PST 2015


On Sunday, 8 November 2015 at 21:57:55 UTC, Alex Parrill wrote:
> Post what you're trying to do if you want an example.

$ cat test.d
import std.stdio;

//void foo(Stream in_stream, Stream out_stream) // I want 
something like this
void foo(File in_stream, File out_stream)
{
         in_stream.seek(3); // BUG

         string line;
         while ((line = in_stream.readln()) !is null)
                 out_stream.write(line);
}

void main(string[] args)
{
         foo(stdin, stdout);
}
$ cat test.txt
Line 0
Line 1
Line 2
$ gdc -o test test.d
$ ./test <test.txt
e 0
Line 1
Line 2
$ cat test.txt | ./test
std.exception.ErrnoException at ../../../src/libphobos/std/stdio.d(595): Could not seek in file `' (Illegal seek)
$


More information about the Digitalmars-d-learn mailing list