fork download
  1. use std::io::stdin;
  2. use std::io::BufRead;
  3. use std::io::BufReader;
  4.  
  5. use std::io;
  6.  
  7. fn main() {
  8. let mut input = String::new(); // Create a mutable string to hold the input
  9. println!("Enter something:"); // Prompt the user
  10. io::stdin().read_line(&mut input) // Read a line from standard input
  11. .expect("Failed to read line"); // Handle potential errors
  12. println!("You entered: {}", input.trim()); // Print the input, trimming whitespace
  13. }
  14.  
Success #stdin #stdout 0.01s 5288KB
stdin
hello
stdout
Enter something:
You entered: hello