Expected A Literal Error In Rust
- Authors
- Name
- Brent
Rust error for println! error: expected a literal / format argument must be a string literal
Error
fn main() {
let c = "hello";
println!(c);
}
Output
error: expected a literal
--> main.rs:3:14
|3 | println!(c);
| ^^
Fix For Error
You need to add the string {}
like below, it is a template where will be replaced by the next argument passed to println!.
fn main() {
let c = "hello";
println!("{}", c);
}
Output
hello