From the course: Rust Essential Training

Unlock the full course today

Join today to access over 22,500 courses taught by industry experts or purchase this course individually.

Standard input

Standard input - Rust Tutorial

From the course: Rust Essential Training

Start my 1-month free trial

Standard input

- [Instructor] If we want the user to be able to interact with our program and provide input, one of the simplest ways to do that is through these standard input stream. Which allows the user to type a message into the command line that our program can then read and use. Functions for working with standard input are included in the rest standard libraries IO module. The IO module is not included in the prelude, so to use it we'll need to manually import it at the top of our program with a use statement. Now, after the user enters a message into the command line, when our program goes to read it from the standard input stream, we'll need a place to store it. The data will come as a string, so let's create a new string named buffer. This new buffer string is currently empty, but it's mutable. So we'll be able to update it when we receive the input message. We don't know how long the user's message will be but that's okay…

Contents