You are on page 1of 1

Chapter 1 Printing on the Terminal

you get a compilation error too, as the placeholders inside the first argument are more
numerous than the arguments after the first argument; that is, there is a placeholder that
doesn't have any corresponding argument.
Instead, the corresponding statements in the C language do not raise compilation
errors, but instead cause the compiled program to crash or misbehave.

Printing Several Lines of Text


So far, we wrote programs that print only one line. But a single statement can print
several lines; in this way:

print!("First line\nSecond line\nThird line\n");

This will print:

First line
Second line
Third line

The sequence of characters \n, where n stands for “new line”, is transformed by
the compiler into the character sequence that represents the line terminator for the
currently used operating system.
Given that it is very common to go to a new line only once for every printing
statement, and just at the end of the statement, another macro, "println", has been
added to the Rust standard library. It’s used in this way:

println!("text of the line");

This statement is equivalent to:

print!("text of the line\n");

Calling this println macro (whose name is to be read “print line”) is equivalent to
calling print with the same arguments, and then outputting a line terminator.

You might also like