Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

writeln() or writefln()?

Tags:

d

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.

like image 788
KarlM Avatar asked Mar 29 '11 06:03

KarlM


2 Answers

Yes, writeln is only available in D2's standard library.

like image 78
Vladimir Panteleev Avatar answered Sep 22 '22 07:09

Vladimir Panteleev


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.");
}
like image 27
dsimcha Avatar answered Sep 25 '22 07:09

dsimcha