Created
November 28, 2021 11:04
-
-
Save 73nko/ecb5ddce2a04cf3aa05778013a6c95b9 to your computer and use it in GitHub Desktop.
Read Lines in a File Rust
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let mut items: Vec<usize> = include_str!("../input.txt") | |
.lines() | |
.map(|i| i.parse().unwrap()) | |
.collect(); | |
// Or | |
fn read_ints(path: &str) -> Vec<i32> { | |
let mut out: Vec<i32> = Vec::new(); | |
let lines = util::read_lines(path).unwrap(); | |
for line in lines { | |
let num = line.unwrap().parse::<i32>().unwrap(); | |
out.push(num); | |
} | |
out | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment