Exerpad
🔥 0
0 XP
Exercise 3 · Chapter: StringsRequired+50 XP

Fix the String

This code tries to push more text onto a string, but it doesn't compile! The variable needs to be a String (not a &str) and it needs to be mutable.

Fix the code so it prints:

Hello, world!

Hint: Change the string literal into a String using String::from() and don't forget to make it mut!

rust
fn main() {
let greeting = "Hello";
greeting.push_str(", world!");
println!("{}", greeting);
}
Output
Run your code to see the output here.