Hello World for D看起来像这样:
import std.stdio;
void main(string[] args)
{
writeln("Hello World, Reloaded");
}
来自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_
这是D1 / D2吗?图书馆的东西?看来,writefln是一个stdio库函数,而writeln则不是。
答案 0 :(得分:7)
是的,writeln
仅适用于D2的标准库。
答案 1 :(得分:4)
正如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.");
}