Pagini recente » Cod sursa (job #1133006) | Cod sursa (job #1632090) | Cod sursa (job #1371674) | Cod sursa (job #222950) | Cod sursa (job #2685416)
use std::fs::File;
use std::path::Path;
use std::io::{self, BufRead};
use std::io::prelude::*;
fn main() {
println!("Hello, world!");
let path = Path::new("adunare.in");
let inf = File::open(path).expect("Error opening if");
let lines = io::BufReader::new(inf).lines();
let mut s = 0;
for line in lines {
let line = line.expect("Line read error");
println!("Read: {}", line);
let n: i32 = line.parse().expect("Number expected");
s+=n;
}
let mut of = File::create("adunare.out").expect("Error creating file");
of.write(s.to_string().as_bytes()).expect("Unable to write");
}