www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - example code fails, std.stream

--0016e64651b4d24e04049462b89a
Content-Type: text/plain; charset=UTF-8

I have this little program:

import std.stdio;
import std.stream;


void main ()
{
Stream file = new BufferedFile("spec.txt");
 foreach(ulong n, string line; file) {
stdout.writefln("line %d: %s",n,line);
 }
file.close();
}

which is basicall a cut-n-paste from
http://digitalmars.com/d/2.0/phobos/std_stream.html
which fails with:
solvejk.d(8): Error: function std.stream.Stream.opApply (scope int
delegate(ref char[]) dg) is not callable using argument types (int
delegate(ref ulong __apply
Arg0, ref string __applyArg1))
solvejk.d(8): Error: cannot implicitly convert expression (__foreachbody765)
of type int delegate(ref ulong __applyArg0, ref string __applyArg1) to int
delegate
(ref ulong n, ref wchar[] line)


This is on windows and dmd is Digital Mars D Compiler v2.050
downloded from http://ftp.digitalmars.com/dmd.2.050.zip (link from dmd
annonce list)

where to go?

--0016e64651b4d24e04049462b89a
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

I have this little program:<div><br></div><div><div>import std.stdio;</div>=
<div>import std.stream;</div><div><br></div><div><br></div><div>void main (=
)=C2=A0</div><div>{</div><div><span style=3D"white-space:pre-wrap">	</span>=
Stream file =3D new BufferedFile(&quot;spec.txt&quot;);</div>


<div><span style=3D"white-space:pre-wrap">	</span>foreach(ulong n, string l=
ine; file) {</div><div><span style=3D"white-space:pre-wrap">		</span>stdout=
.writefln(&quot;line %d: %s&quot;,n,line);</div>
<div><span style=3D"white-space:pre-wrap">	</span>}</div><div><span style=
=3D"white-space:pre-wrap">	</span>file.close();</div><div>}</div><div><br><=
/div></div><div>which is basicall a cut-n-paste from=C2=A0<a href=3D"http:/=
/digitalmars.com/d/2.0/phobos/std_stream.html" target=3D"_blank">http://dig=
italmars.com/d/2.0/phobos/std_stream.html</a></div>


<div>which fails with:</div><div><div>solvejk.d(8): Error: function std.str=
eam.Stream.opApply (scope int delegate(ref char[]) dg) is not callable usin=
g argument types (int delegate(ref ulong __apply</div><div>Arg0, ref string=
 __applyArg1))</div>


<div>solvejk.d(8): Error: cannot implicitly convert expression (__foreachbo=
dy765) of type int delegate(ref ulong __applyArg0, ref string __applyArg1) =
to int delegate</div><div>(ref ulong n, ref wchar[] line)</div></div><div>


<br></div><div><br></div><div>This is on windows and dmd is=C2=A0Digital Ma=
rs D Compiler v2.050</div><div>downloded from=C2=A0<span class=3D"Apple-sty=
le-span" style=3D"font-family: arial, sans-serif; font-size: 12.5px; border=
-collapse: collapse; "><a href=3D"http://ftp.digitalmars.com/dmd.2.050.zip"=
 target=3D"_blank" style=3D"color: rgb(0, 0, 204); ">http://ftp.digitalmars=
.com/dmd.2.050.zip</a>=C2=A0(link from dmd annonce list)</span></div>

<div><span class=3D"Apple-style-span" style=3D"font-family: arial, sans-ser=
if; font-size: 12.5px; border-collapse: collapse; "><br></span></div><div><=
span class=3D"Apple-style-span" style=3D"font-family: arial, sans-serif; fo=
nt-size: 12.5px; border-collapse: collapse; ">where to go?</span></div>

<div><br></div><div><br></div>

--0016e64651b4d24e04049462b89a--
Nov 06 2010