How to Use stdin and stdout in Rust

Read user input with io::stdin().read_line() and display output with println! in Rust.

Use std::io to read from standard input and println! to write to standard output.

use std::io;

fn main() {
    println!("Please input your guess.");
    let mut guess = String::new();
    io::stdin()
        .read_line(&mut guess)
        .expect("Failed to read line");
    println!("You guessed: {guess}");
}