Logo

Programming-Idioms

History of Idiom 120 > diff from v23 to v24

Edit summary for version 24 by bratushka.v:
New Rust implementation by user [bratushka.v]

Version 23

2016-10-02, 16:15:21

Version 24

2016-11-17, 14:33:33

Idiom #120 Read integer from stdin

Read an integer value from the standard input into variable n.

Idiom #120 Read integer from stdin

Read an integer value from the standard input into variable n.

Code
fn get_input() -> String {
    let mut buffer = String::new();
    std::io::stdin().read_line(&mut buffer).expect("Failed");
    buffer
}

let x = get_input().trim().parse::<i64>().unwrap();
Comments bubble
Change i64 to what you expect to get. Do not use `unwrap()` if you're not sure it will be parsed correctly.