# Rust print without newline: print! vs println!

> Print in Rust with or without a newline. Compare print! and println!, flush stdout for prompts, and avoid repeated stdout locking.

HTML: https://rustprint.com/output/print-and-println/

Use `print!` when Rust should write to stdout without adding a newline. Use `println!` when the output should end with a newline. If a no-newline prompt must appear immediately, call `stdout().flush()` after `print!`.

**Primary output with and without a newline**

```rust
print!("building...");
println!(" done");
```

## print! vs println!

| Macro      | Destination | Adds a newline |
| ---------- | ----------- | -------------- |
| `print!`   | stdout      | no             |
| `println!` | stdout      | yes            |

Both macros use Rust's normal formatting syntax. The difference here is the line ending, not how values are formatted.

## Print without a newline

`print!` leaves the cursor immediately after the formatted text. It 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.

## Print without a newline and show it immediately

For an interactive prompt, import `std::io::Write`, call `print!`, and then flush stdout:

**No-newline prompt with an explicit stdout flush**

```rust
use std::io::{self, Write};

print!("Continue? [y/N] ");
io::stdout().flush().unwrap();
```

The `Write` trait import is required for the `flush()` method. The dedicated [flush stdout guide](/output/flush-stdout/index.md) covers that trait requirement and the common compiler error when it is missing.

## Use println! for complete lines

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

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

## Repeated writes

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](/output/output-macros/index.md) contains a CI-checked example of that pattern.

## Primary output only

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!](/output/stderr-eprint-eprintln/index.md).

If the main question is which output macro fits a destination and newline requirement, use the [Output Macro Chooser](/tools/output-macro-chooser/).

## Sources

- [print!](https://doc.rust-lang.org/std/macro.print.html)
- [println!](https://doc.rust-lang.org/std/macro.println.html)

## Related RustPrint guides

- [Flush stdout in Rust](/output/flush-stdout/index.md): Flush Rust stdout after print! so prompts appear immediately, and fix flush() by importing std::io::Write.
- [Rust output macros: print!, eprintln!, write!, and format!](/output/output-macros/index.md): Choose the right Rust output macro for stdout, stderr, an owned String, or an existing writer, including newline, flushing, and buffering behavior.
- [Rust stderr: eprint! and eprintln!](/output/stderr-eprint-eprintln/index.md): Print Rust errors, warnings, and progress messages to stderr with eprint! and eprintln!, keeping machine-readable stdout output clean.
- [Rust write! and writeln! - format into strings, files, and buffers](/output/write-and-writeln/index.md): Use Rust write! and writeln! to format directly into String buffers, byte writers, files, sockets, and other write_fmt destinations.
