Created
August 2, 2014 15:03
-
-
Save MatejLach/d23e5ec019c48298045e to your computer and use it in GitHub Desktop.
Showcases standard input in Rust...
This file contains hidden or 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
use std::io; | |
fn main() { | |
println!("Type something:"); | |
let input = io::stdin() | |
.read_line() // read user input | |
.ok().expect("unable to read input!"); // Display this in case of a problem reading user input | |
// convert to &str and get rid of the newline | |
println!("You just typed \"{}\" into the console.\nCongratulations!", input.as_slice().trim_right_chars('\n')); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment