Reputation: 1662
Hello World for D looks like this:
import std.stdio;
void main(string[] args)
{
writeln("Hello World, Reloaded");
}
from http://www.digitalmars.com/d/
But when I compile that with gdc-4.4.5 I get:
hello.d:5: Error: undefined identifier writeln, did you mean function writefln?
hello.d:5: Error: function expected before (), not __error of type _error_
Is this a D1/D2 thing? A library thing? It seems odd that writefln is a stdio library function and writeln is not.
Upvotes: 8
Views: 2652
Reputation: 68770
As CyberShadow mentions, writeln
is only in D2. The difference between them is writeln
just prints its arguments as-is, while writefln
interprets its first argument as a format string, like C's printf
.
Example:
import std.stdio;
void main() {
// Prints "There have been 44 U.S. presidents." Note that %s can be used
// to print the default string representation for any type.
writefln("There have been %s U.S. presidents.", 44);
// Same thing
writeln("There have been ", 44, " U.S. presidents.");
}
Upvotes: 5
Reputation: 25187
Yes, writeln
is only available in D2's standard library.
Upvotes: 7