Where is stdout?

Andrej Mitrovic andrej.mitrovich at gmail.com
Wed Aug 4 12:11:09 PDT 2010


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 at 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
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20100804/1bf1cbae/attachment.html>


More information about the Digitalmars-d mailing list