Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the preferred console output method in modern D?

Tags:

console

d

Most of the D language tutorials I've seen use printf to output text to the console, but that can't be right. I know that D provides direct access to the C/C++ libraries, but shouldn't D's console output function be used instead? What is the preferred method for outputting text (formatted or otherwise) to a console window?

like image 364
Maxpm Avatar asked Apr 01 '11 02:04

Maxpm


People also ask

What is the console output?

The Console is a window of the operating system through which users can interact with system programs of the operating system or with other console applications. The interaction consists of text input from the standard input (usually keyboard) or text display on the standard output (usually on the computer screen).

What is console WriteLine () good for?

Write is used to print data without printing the new line, while Console. WriteLine is used to print data along with printing the new line.

What is the use of console ReadLine () in C#?

The C# readline method is mainly used to read the complete string until the user presses the Enter key or a newline character is found. Using this method, each line from the standard data input stream can be read. It is also used to pause the console so that the user can take a look at the output.

What are console methods?

A Console method is an object used to access the browser debugging console. With the help of console methods, we can print messages, warnings, and errors to the browser console, which is helpful for debugging purposes.


1 Answers

Within the module std.stdio, you'll find write and friends: writeln, writef, and writefln.


write just takes each argument, converts it to a string, and outputs it:

import std.stdio;

void main()
{
    write(5, " <- that's five"); // prints: 5 <- that's five
}

writef treats the first string as a format-specifier (much like C's printf), and uses it to format the remaining arguments:

import std.stdio;

void main()
{
    writef("%d %s", 5, "<- that's five"); // prints: 5 <- that's five
}

The versions ending with "ln" are equivalent to the version without it, but also append a newline at the end of printing. All versions are type-safe (and therefore extensible).

like image 119
GManNickG Avatar answered Sep 19 '22 14:09

GManNickG