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

Related questions

2 answers 350 views
350 views asked Oct 20, 2022 by avibootz
1 answer 285 views
2 answers 366 views
1 answer 238 views
...