I am making a program that asks a user's age:
use std::io;
fn main() {
println!("How Old Are You?");
let mut age = String::new();
io::stdin().read_line(&mut age).expect("Failed to get age");
println!("You are {} years old!", age);
}
Once the user enters their age (8
for example) read_line
inserts a '\n'
to what the user inputs. The result looks like
You are 8
years old!
I know I can use something like this to remove the '\n'
before displaying the age:
let age = age.trim();
Is there an alternative I could use to read user input simply that won't add anything to the variable.