Avatar ·

Error in Rust: "expected a literal" when using println! — how to fix?

Hi! I just started learning Rust and encountered an error I can't understand. I'm trying to print a variable value using println!, but the compiler complains. Here's my code: ```rust fn main() { let name = "Alice"; println!("Hello, " + name + "!"); } ``` The compiler outputs: ``` error: expected a literal --> src/main.rs:3:23 | 3 | println!("Hello, " + name + "!"); | ^ | help: format argument must be a string literal ``` I expected the string to concatenate like in Python or JavaScript, but Rust clearly doesn't want to work that way. Why? How do I properly output variables? I tried removing concatenation and writing just `println!("Hello, name!")` — then it literally prints "Hello, name!", not the variable value. Please tell me what I'm doing wrong? I found mentions of macros in the documentation but didn't fully understand. I need a simple example of how to print a string with a variable. Thanks in advance! <<>>

Why the error occurs