影片地址
頭條地址:https://www.ixigua.com/i676544267458235648...
B站地址:https://www.bilibili.com/video/av78062009?...
網易雲課堂地址:https://study.163.com/course/introduction....
github地址
獲取命令列引數
透過std::env來獲取命令列引數,例子如下:
use std::env;
fn main() {
let args: Vec<String> = env::args().collect();
println!("{:?}", args);
}
還可以列印引數個數:
use std::env;
fn main() {
let args: Vec<String> = env::args().collect();
println!("size = {}", args.len());
for argument in args {
println!("{}", argument);
}
}
將引數值儲存進變數
use std::env;
fn main() {
let args: Vec<String> = env::args().collect();
println!("size = {}", args.len());
let a = &args[1];
println!("a = {}", a);
let b = &args[2];
println!("b = {}", b);
}
本作品採用《CC 協議》,轉載必須註明作者和本文連結