Skip to content

print! vs println!

print! and println! both write formatted text to standard output. The difference is the newline: println! appends one, while print! leaves the cursor immediately after the formatted text.

EXAMPLE: CI-CHECKEDCOMPILED · examples/format-output/src/output_pages.rs#output-print-println
print!("building...");
println!(" done");

For ordinary terminal output, println! is the default. It produces a complete line and works naturally with line-buffered stdout.

Rust documents the newline emitted by println! as a line feed (\n) on every platform.

print! is useful for prompts, progress fragments, and output that intentionally continues on the same line. The important catch is buffering.

When stdout is connected to a terminal it is commonly line-buffered, so output without a newline may remain in the buffer. If the user must see the text immediately, flush stdout explicitly.

Both macros lock stdout on each call. For occasional output that is exactly what you want. In a hot loop, repeatedly acquiring the lock can become avoidable overhead.

Lock stdout once and use write! or writeln! through the locked handle when you have many writes. The output macros overview contains a CI-checked example of that pattern.

The standard library documentation positions these macros for primary program output. If text is an error, warning, or progress message that should stay separate from piped data, use stderr through eprint! or eprintln!.