Rust program to read a string from the user


Program to read a string from the user

Rust Programming Language


Program to read a string from the user


Problem


In this program, we will read a string from the user using the read_lin() function and print the input string.


Input


// Rust program to read a string 
// from the user

fn main(){
   let mut Str = String::new();
   
   println!("Enter String: ");
   std::io::stdin().read_line(&mut Str);
   
   println!("String is: {}", Str);
}{codeBox}


Output


Enter String: 
Hello World
String is: Hello World{codeBox}


Explanation


Here, we created a string variable Str. Then we read the string from the user using the read_line() function and printed the input string.



Post a Comment