ADVERTISEMENT
ADVERTISEMENT

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 »


ADVERTISEMENT
ADVERTISEMENT


Comments and Discussions!



ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.