Home »
Rust »
Rust Programs
Rust program to demonstrate the command line arguments
Rust Example: Write a program to demonstrate the command line arguments.
Submitted by Nidhi, on November 26, 2021
Problem Solution:
In this program, we will pass arguments at runtime and print them.
Program/Source Code:
The source code to demonstrate the command line arguments is given below. The given program is compiled and executed on UBUNTU 18.04 successfully.
// Rust program to demonstrate the
// command line arguments
fn main(){
let args = std::env::args();
// Print all arguments passed at command line
println!("Arguments: ");
for arg in args {
println!("{}",arg);
}
}
Output:
Compile:
$ rustc main.rs
Execute:
$ ./main One Two Three
Arguments:
./main
One
Two
Three
Explanation:
In the main() function, we printed the command line arguments.
Rust Miscellaneous Programs »