std.stream example
Gide Nwawudu
gide at btinternet.com
Mon Apr 28 15:44:18 PDT 2008
On Mon, 28 Apr 2008 13:36:18 +0000 (UTC), "Me Here"
<p9e883002 at sneakemail.com> wrote:
>
>I just tried to compile the following example ffrom the std.stream docs:
>
>import std.stdio;
>import std.stream;
>
>int main (char[][] args) {
>
> Stream file = new BufferedFile( "myfile" );
> foreach( ulong n, string line; file ) {
> writefln( "line %d: %s", n,line );
> }
> file.close();
> return 0;
>}
>
>I'm getting:
>
>
>fhash.d(31): function std.stream.Stream.opApply (int delegate(ref char[] line))
>does not match parameter types (int delegate(ref ulong __applyArg0, ref invariant(char)[] __applyArg1))
>
>fhash.d(31): Error: cannot implicitly convert expression (__foreachbody15)
>of type int delegate(ref ulong __applyArg0, ref invariant(char)[] __applyArg1)
>to int delegate(ref ulong n, ref wchar[] line)
>
>Have I got my libraries screwed up?
>Or c&p the example incorrectly?
>Or is the example just out of date or otherwise screwed?
>
>Cheers, b.
> Or is the example just out of date ...
Example is wrong.
D1 declares a string as char[], D2 declares it as invariant(char)[].
It does not compile because the line variable being passed to
Stream.onApply should be mutable.
So foreach( ulong n, string line; file ) changes to:
foreach( ulong n, char[] line; file )
- or -
foreach( ulong n, ref char[] line; file )
Gide
More information about the Digitalmars-d
mailing list