How to use stdin and stdout

Read user input with io::stdin().read_line() and display results using 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}");
}