read_line insisting on keeping newline
This commit is contained in:
parent
fbe19464eb
commit
3bb544989b
@ -1,17 +1,19 @@
|
||||
use std::io;
|
||||
use std::io::{self, Write};
|
||||
use rand::Rng;
|
||||
use std::cmp::Ordering;
|
||||
// use std::str;
|
||||
|
||||
fn main() {
|
||||
println!("Let's play the guessing game!");
|
||||
let secret_number = rand::thread_rng().gen_range(1..=100);
|
||||
loop {
|
||||
println!(" What's your guess?");
|
||||
print!("What's your guess? ");
|
||||
io::stdout().flush().unwrap();
|
||||
let mut guess = String::new();
|
||||
io::stdin()
|
||||
.read_line(&mut guess)
|
||||
.expect("Sorry; something didn't quite work.");
|
||||
let guess: u32 = match guess.trim().parse() {
|
||||
let guess: u32 = match guess.trim_end().parse() {
|
||||
Ok(num) => num,
|
||||
Err(_) => continue,
|
||||
};
|
||||
@ -23,5 +25,6 @@ fn main() {
|
||||
break;
|
||||
}
|
||||
}
|
||||
// io::stdout().flush().unwrap();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user