digitalmars.D - Where is stdout?
- Andrej Mitrovic <andrej.mitrovich gmail.com> Aug 04 2010
- Jonathan M Davis <jmdavisprog gmail.com> Aug 04 2010
- Andrej Mitrovic <andrej.mitrovich gmail.com> Aug 04 2010
From TDPL, page 161:
import std.conv;
void writeln(T...)(T args)
{
foreach (arg; args)
{
stdout.rawWrite(to!string(arg));
}
stdout.rawWrite('\n');
stdout.flush();
}
void main()
{
writeln("test");
}
test.d(10): Error: undefined identifier stdout
Aug 04 2010
On Wednesday, August 04, 2010 11:38:28 Andrej Mitrovic wrote:From TDPL, page 161: import std.conv; void writeln(T...)(T args) { foreach (arg; args) { stdout.rawWrite(to!string(arg)); } stdout.rawWrite('\n'); stdout.flush(); } void main() { writeln("test"); } test.d(10): Error: undefined identifier stdout
std.stdio - which is what you usually import for doing I/O. Of course, it actually defines writeln(), so it's not like you need to write it yourself - not to mention, you can always just look at stdio.d in the phobos src (which gets downloaded with dmd) to see its exact implementation if you want to. - Jonathan M Davis
Aug 04 2010
--0016363ba5de42853d048d0432d5
Content-Type: text/plain; charset=ISO-8859-1
Okay, this works:
import std.conv, std.stdio;
void writeln(T...)(T args)
{
foreach (arg; args)
{
stdout.rawWrite(to!string(arg));
}
stdout.rawWrite("\n");
stdout.flush();
}
void main()
{
writeln("test");
}
But I had to replace '\n' with "\n", otherwise I get some errors back:
test.d(11): Error: template std.stdio.File.rawWrite(T) does not match any
function template declaration
test.d(11): Error: template std.stdio.File.rawWrite(T) cannot deduce
template function from argument types !()(char)
test.d(17): Error: template instance test.writeln!(string) error
instantiating
Which probably makes sense if rawWrite expects a string and not a char.
Thanks Jonathan.
On Wed, Aug 4, 2010 at 8:52 PM, Jonathan M Davis <jmdavisprog gmail.com>wrote:
On Wednesday, August 04, 2010 11:38:28 Andrej Mitrovic wrote:
From TDPL, page 161:
import std.conv;
void writeln(T...)(T args)
{
foreach (arg; args)
{
stdout.rawWrite(to!string(arg));
}
stdout.rawWrite('\n');
stdout.flush();
}
void main()
{
writeln("test");
}
test.d(10): Error: undefined identifier stdout
std.stdio - which is what you usually import for doing I/O. Of course, it
actually defines writeln(), so it's not like you need to write it yourself
- not
to mention, you can always just look at stdio.d in the phobos src (which
gets
downloaded with dmd) to see its exact implementation if you want to.
- Jonathan M Davis
--0016363ba5de42853d048d0432d5
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Okay, this works:<br><br>import std.conv, std.stdio;<br><br>void writeln(T.=
..)(T args)<br>{<br>=A0=A0=A0 foreach (arg; args)<br>=A0=A0=A0 {<br>=A0=A0=
=A0=A0=A0=A0=A0 stdout.rawWrite(to!string(arg));<br>=A0=A0=A0 }<br>=A0=A0=
=A0 stdout.rawWrite("\n");<br>
=A0=A0=A0 stdout.flush();<br>}<br><br>void main()<br>{<br>=A0=A0=A0 writeln=
("test");<br>}<br><br>But I had to replace '\n' with &quo=
t;\n", otherwise I get some errors back:<br><br>test.d(11): Error: tem=
plate std.stdio.File.rawWrite(T) does not match any function template decla=
ration<br>
test.d(11): Error: template std.stdio.File.rawWrite(T) cannot deduce templa=
te function from argument types !()(char)<br>test.d(17): Error: template in=
stance test.writeln!(string) error instantiating<br><br>Which probably make=
s sense if rawWrite expects a string and not a char.<br>
<br>Thanks Jonathan.<br><br><div class=3D"gmail_quote">On Wed, Aug 4, 2010 =
at 8:52 PM, Jonathan M Davis <span dir=3D"ltr"><<a href=3D"mailto:jmdavi=
sprog gmail.com">jmdavisprog gmail.com</a>></span> wrote:<br><blockquote=
class=3D"gmail_quote" style=3D"margin: 0pt 0pt 0pt 0.8ex; border-left: 1px=
solid rgb(204, 204, 204); padding-left: 1ex;">
<div><div></div><div class=3D"h5">On Wednesday, August 04, 2010 11:38:28 An=
drej Mitrovic wrote:<br>
> From TDPL, page 161:<br>
><br>
> import std.conv;<br>
><br>
> void writeln(T...)(T args)<br>
> {<br>
> =A0 =A0 foreach (arg; args)<br>
> =A0 =A0 {<br>
> =A0 =A0 =A0 =A0 stdout.rawWrite(to!string(arg));<br>
> =A0 =A0 }<br>
> =A0 =A0 stdout.rawWrite('\n');<br>
> =A0 =A0 stdout.flush();<br>
> }<br>
><br>
> void main()<br>
> {<br>
> =A0 =A0 writeln("test");<br>
> }<br>
><br>
> test.d(10): Error: undefined identifier stdout<br>
<br>
</div></div>std.stdio - which is what you usually import for doing I/O. Of =
course, it<br>
actually defines writeln(), so it's not like you need to write it yours=
elf - not<br>
to mention, you can always just look at stdio.d in the phobos src (which ge=
ts<br>
downloaded with dmd) to see its exact implementation if you want to.<br>
<font color=3D"#888888"><br>
- Jonathan M Davis<br>
</font></blockquote></div><br>
--0016363ba5de42853d048d0432d5--
Aug 04 2010









Jonathan M Davis <jmdavisprog gmail.com> 