rust read user input code example

Example 1: rust input

//Declare dependencies
use std::io::stdin;

fn main() {
	//Declare a mutable input string
    let mut input_string = String::new();
    stdin.read_line(&mut input_string)
    	.ok()
        .expect("Failed to read line");
}

Example 2: rust take user input

//Declare dependencies
use std::io::stdin;

fn main() {
	//Declare a mutable input string
    let mut input_string = String::new();
    stdin().read_line(&mut input_string)
    	.ok()
        .expect("Failed to read line");
}

Tags:

Rust Example