Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- extern crate xml;
- use std::io;
- use std::io::BufRead;
- use std::io::BufReader;
- use std::fs::File;
- fn main() {
- println!("Hello, world!");
- let stdin = io::stdin();
- let b = false;
- // let mut handle :Box<io::BufRead>;
- // if b {
- // handle = Box::new(stdin.lock());
- // } else {
- // let file = File::open("in.txt").unwrap();
- // handle = Box::new(BufReader::new(file));
- // };
- let mut stdioHandle;
- let mut fileHandle;
- let handle :&mut io::BufRead;
- if b {
- stdioHandle = stdin.lock();
- handle = &mut stdioHandle;
- } else {
- let file = File::open("in.txt").unwrap();
- fileHandle = BufReader::new(file);
- handle = &mut fileHandle;
- };
- let mut line = String::new();
- handle.read_line(&mut line).unwrap();
- println!("line: '{}'", line);
- }
Add Comment
Please, Sign In to add comment