How to read user input from stdin in Rust

1 Answer

0 votes
use std::io;

fn main() {
    println!("Please enter a string: ");

    let mut str = String::new();
    
    io::stdin().read_line(&mut str); 
    
    println!("str = {}", str);
} 
 
 
 
 
/*
run:
 
Please enter a string: rust
str = rust
 
*/

 



answered Apr 15, 2023 by avibootz
...