Writeln () or writefln ()?

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 this 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? What is a library? It seems strange that writefln is a library function of stdio, while writeln is not.

+7
source share
2 answers

Yes, writeln is only available in the standard D2 library.

+7
source

As CyberShadow mentions, writeln is only in D2. The difference between the two is that writeln just prints its as-is arguments, and writefln interprets its first argument as a format string, such as C printf .

Example:

 import std.stdio; void main() { // Prints "There have been 44 US presidents." Note that %s can be used // to print the default string representation for any type. writefln("There have been %s US presidents.", 44); // Same thing writeln("There have been ", 44, " US presidents."); } 
+4
source

All Articles