How to read user input in Rust?

前端 未结 10 1917
情歌与酒
情歌与酒 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:27

    As of 17 April 2015 from mdcox on the mozilla rust irc.

    use std::io;
    
    fn main() {
        let mut stdin = io::stdin();
        let input = &mut String::new();
    
        loop {
            input.clear();
            stdin.read_line(input);
            println!("{}", input);
        }
    }
    

提交回复
热议问题