Capturing User Input

Learn how to use the terminal to ask the user to type their name and receive the result after capturing input.

Output text on the terminal

Most computer programs operate in a cycle of accepting input from the user and transforming that into some form of hopefully useful output.

A calculator without buttons is pretty useless, and a computer program without input is equally limited. We used println! in “Hello, world” to output text and we can use read_line() to accept data from the terminal.

We can run the following program by typing cargo run in a terminal.

Get hands-on with 1200+ tech skills courses.