Hello World for D看起来像这样:
import std.stdio;
void main(string[] args)
{
writeln("Hello World, Reloaded");
}
Run Code Online (Sandbox Code Playgroud)
来自http://www.digitalmars.com/d/
但是当我用gdc-4.4.5编译它时,我得到:
hello.d:5: Error: undefined identifier writeln, did you mean function writefln?
hello.d:5: Error: function expected before (), not __error of type _error_
Run Code Online (Sandbox Code Playgroud)
这是D1/D2的东西吗?图书馆的东西?看来,writefln是一个stdio库函数,而writeln则不是.
正如 CyberShadow 所提到的,writeln仅在 D2 中。它们之间的区别writeln只是按原样打印其参数,而writefln将其第一个参数解释为格式字符串,如 C 的printf。
例子:
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.");
}
Run Code Online (Sandbox Code Playgroud)