Loading... # 0x00 命令行参数的使用 Go的命令行参数储存在切片os.Args中 ```go for i,s := range os.Args{ fmt.Println("Args[%d]=%s",i,s) } ``` # 0x01 flag包对命令行参数解析 flag包 ```go flag.Type("Flag Name",Default Value,"Help Message") *Tpye ``` 使用实例: ```go var i = flag.Int("i" , 1 ,"number") func main(){ flag.Pares() fmt.Println(*n) } ``` ```shell #./main -h Usage of ./main: -h int number (default 1) #./main -i 1234 1234 ``` # 0x02 cmd输入 窗口停留等待输入 ```go var i string func main(){ fmt.Scanln(&i) fmt.Println(i) } ``` Last modification:October 24, 2019 © Allow specification reprint Support Appreciate the author AliPayWeChat Like 0 如果觉得我的文章对你有用,请随意赞赏