digitalmars.D - Where is stdout?
- Andrej Mitrovic (16/16) Aug 04 2010 From TDPL, page 161:
- Jonathan M Davis (6/26) Aug 04 2010 std.stdio - which is what you usually import for doing I/O. Of course, i...
- Andrej Mitrovic (25/53) Aug 04 2010 Okay, this works:
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
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
Aug 04 2010









Jonathan M Davis <jmdavisprog gmail.com> 