📜  rust 从标准输入读取行并返回一个 vec - Rust 代码示例

📅  最后修改于: 2022-03-11 14:49:25.138000             🧑  作者: Mango

代码示例1
//read lines from stdin and return a vector
fn readlines() -> Vec {
    use std::io::prelude::*;
    let stdin = std::io::stdin();
    let v = stdin.lock().lines().map(|x| x.unwrap()).collect();
    v
}
// sample usage
fn main() {
    let f = readlines();
    println!("{:?}", f); 
}