Answers for "rust read lines from stdin"

0

rust read lines from stdin and return a vec

//read lines from stdin and return a vector
fn readlines() -> Vec<String> {
    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); 
}
Posted by: Guest on March-12-2021

Browse Popular Code Answers by Language