This question already has an answer here:
- Why doesn't my user input from stdin match correctly? 3 answers
In the following code, I was expecting the message “wow” to be printed when the user enters “q”, but it does not.
fn main() {
let mut input = String::new();
io::stdin().read_line(&mut input)
.expect("failed to read line");
if input == "q" {
println!("wow") ;
}
}
Why is the message not printed as expected?