ADVERTISEMENT
ADVERTISEMENT

Rust program to read a string from the user

Rust Example: Write a program to read a string from the user.
Submitted by Nidhi, on November 27, 2021

Problem Solution:

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

Program/Source Code:

The source code to read a string from the user is given below. The given program is compiled and executed successfully.

// 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);
}

Output:

Enter String: 
Hello World
String is: Hello World

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.

Rust Miscellaneous Programs »


ADVERTISEMENT
ADVERTISEMENT


Comments and Discussions!



ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.