Salut, je ne comprend pas le buffer et le flush. extrait:
extern crate rand;
use std::io::{stdin, stdout, Write};
use rand::random;
fn main() {
// Write to console
println!("Welcome to this number guessing game!");
print!("Please enter your name: ");
// Make sure the out-buffer is empty
let _ = stdout().flush();
// Create mutable (writeable) string variable
let mut input = String::new();
// Read user input
stdin().read_line(&mut input).expect("Did not enter a correct string");
// Prevent us from accidentally overwriting the username by making it immutable
let player_name: String = input.trim().into();
// Create random number
let number = random::<u32>() % 100 + 1;
// Output what we have so far
println!("Your name is {} and my random number is {}!", player_name, number);
}
+0
-0