我只需要找到一种使用输入进行简单数学运算的方法即可。 advent of code 2019 day 1
我已经尝试了几天use std::fs::File;
use std::io::{BufRead, BufReader, Error};
fn main() -> Result<(), Error> {
let path = "input.txt";
let input = File::open(path)?;
let buffered = BufReader::new(input);
for line in buffered.lines() {
line.parse::<i32>().unwrap();
line / 2;
println!("{:?}", line);
}
Ok(())
}
答案 0 :(得分:0)
如果要编译代码。
use std::fs::File;
use std::io::{BufRead, BufReader, Error};
fn main() -> Result<(), Error> {
let path = "input.txt";
let input = File::open(path)?;
let buffered = BufReader::new(input);
for line in buffered.lines() {
println!("{:?}", line.unwrap().parse::<i32>().unwrap() / 2);
}
Ok(())
}