Rust Programming Tutorial #30 - Reading User Input

preview_player
Показать описание
One of the most important things in a program is to read user input and in this video I show you how you can do this in Rust.

It is done through the stdin struct/stream and in this example we use the read_line method to feed user input from the console into a mutable String.

For more info, check out:

If this video helped you out and you'd like to see more, make sure to leave a like and subscribe to dcode!
Рекомендации по теме
Комментарии
Автор

This is probably the most complicated way to take in input from a non esoteric language

porcelainface
Автор

These tutorials are incredibly helpful. I've done tons of programming before, but Rust confused me a great deal, and you've helped me greatly!

CJBurkey
Автор

I did a tweak in order to check if the user hasn't input anything:
match io::stdin()
.read_line(&mut input) {
Ok(_) => {

if input == "\n" || input.trim().is_empty(){
println!("You didn't say anything.");
} else {
println!("Success! You said: {}", input.to_uppercase());
}
},
Err(e) => {
println!("Oops! Something went wrong: {}", e);
}
}
}

isrj
Автор

Hi,
What if i want no input from user, but i want the console will be stay there and when the user presses an "Enter" key, program can exit. In basic languages, they use "Sleep". In .net, they use Console.WriteLine() with no arguments. What is the rust equivalent ?

kcvinu
Автор

What code editor are you using? Is it vscode? It looks so different. Is it a theme?

arunk
Автор

How to define a 2d array and how to take input from users.
Make more videos.

AbhinandanMishra
Автор

@dcode Why in RUST, If you have to take integer input from user, you will take value as string, then convert into integer.

wwewwf
Автор

Can you use .expect() on the read line?

elijahlucian
Автор

how can we take character as input in rust ??

mabeerkidunia
Автор

@dcode How to take integer input from user?

wwewwf
Автор

how do i get input without new line in prompt?

daniellamariecostales
Автор

how to take user input as an integer horizontally?

syedabdulbasit
Автор

Is there a way to accept int, float as input in Rust?

aloky