valve's

corner

Reading Command Line Arguments in Rust

Since all rust hello world tutorials usually start like this:

1
2
3
fn main(){
  println("Hello, world");
}

It’s unclear where to take command line arguments.

The solution:

1
2
3
4
5
6
use std::os;

fn main(){
  let args: ~[~str] = os::args();
  println(args.to_str());
}

This will give you a vector with strings where first string will be the app being run and the rest is the arguments provided.

rust-0.7

Comments