Printing a string
- We cannot just put a variable in the println! macro. We need to put in a formatting string with placeholders for the values.
- This code will NOT compile, but the compiler will give you a hint how to fix it.
examples/intro/formatting-required/src/main.rs
fn main() { let name = "Foo"; println!(name); }
error: format argument must be a string literal --> examples/intro/formatting_required.rs:3:14 | 3 | println!(name); | ^^^^ | help: you might be missing a string literal to format with | 3 | println!("{}", name); | +++++ error: aborting due to previous error