Skip to content

Instantly share code, notes, and snippets.

@kudrevatykh
Created June 28, 2015 17:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kudrevatykh/32b33c642998fea945a8 to your computer and use it in GitHub Desktop.
Save kudrevatykh/32b33c642998fea945a8 to your computer and use it in GitHub Desktop.
flush example
use std::io;
use std::io::Write;
fn main() {
let s = read_string("aaa");
println!("inputed {}", s);
}
fn read_string(comment: &str) -> String {
print!("{}", comment);
io::stdout().flush().ok().expect("Error flushing");
let mut string: String = String::new();
std::io::stdin().read_line(&mut string)
.ok()
.expect("Error read line!");
return string;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment