Wednesday , November 20 2019

User Input in Rust

In this article, you can find out the way to get the input from the user.

First, you need to know about these things.
std::io, stdin(), read_line(), trim(), and parse().
the above mention things are related to the standard input/output procedure in rust lang.

std::io is the library which will perform the standard inputting buy users.

other things are functions which are belonging to the std:io library.

use std::io;

fn main() {
    let mut data_01 = String::new(); // make a mutable string variable
    println!("Enter the Number 01 please");
    io::stdin().read_line(&mut data_01); //to get input from the user
    let data_01: f64 = data_01.trim().parse().unwrap(); // performing shadowing to convert the type 

    let mut data_02 = String::new(); // make a mutable string variable
    println!("Enter the Number 02 please");
    io::stdin().read_line(&mut data_02); //to get input from the user
    let data_02: f64 = data_02.trim().parse().unwrap();// performing shadowing to convert the type 
    println!("Given Result is: {}",(data_01+data_02));
}

The below mention video you can see each an every step to get the data from user in rust

About Faheem

Faheem
An adaptable and responsible Software Engineer, who enjoys working with computers and the opportunity to learn new skills and work with new technologies is particularly attractive to me.

Check Also

Rust Installation in Windows

In this article, you can see the installation process of rust compiler in Windows. Step …

One comment

  1. Avatar

    Great post. I was checking constantly this blog and I’m impressed! Extremely useful information specifically the last part 🙂 I care for such info a lot. I was seeking this particular information for a long time. Thank you and best of luck.

Leave a Reply

Your email address will not be published.