How to read user input in Rust?

前端 未结 10 1693
情歌与酒
情歌与酒 2021-01-31 07:50

Editor\'s note: This question refers to parts of Rust that predate Rust 1.0, but the general concept is still valid in Rust 1.0.

I intend to

10条回答
  •  爱一瞬间的悲伤
    2021-01-31 08:10

    The question is to read lines from stdin and return a vector. On Rust 1.7:

    fn readlines() -> Vec {
        use std::io::prelude::*;
        let stdin = std::io::stdin();
        let v = stdin.lock().lines().map(|x| x.unwrap()).collect();
        v
    }
    

提交回复
热议问题