Skip to content

Instantly share code, notes, and snippets.

Created Oct 6, 2021
What would you like to do?
Function to get the input from stream
fn main() {
print!("Please enter some text: ");
let input=get_input();
println!("Input = {0}", input);
fn get_input() -> String {
use std::io::{stdin,stdout,Write};
let mut s=String::new();
let _=stdout().flush();
stdin().read_line(&mut s).expect("Did not enter a correct string");
if let Some('\n')=s.chars().next_back() {
if let Some('\r')=s.chars().next_back() {
return s;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment