Rust - flush STDOUT - read STDIN
- We use print! and not println!
- use std::io::Write; adds the flush
examples/stdin/hello-name-chomp-flush/src/main.rs
use std::io; use std::io::Write; fn main() { let mut name = String::new(); print!("Please type in your name: "); io::stdout().flush().expect("Oups"); io::stdin() .read_line(&mut name) .expect("Failed to get input"); name = name.trim_end().to_string(); println!("Hello {}, how are you?", name); }