Go 中用range关键字获取命令行参数

1 package main
  2 
  3 import "fmt"
  4 import "os"
  5 
  6 func main(){
  7     fmt.Println(len(os.Args))
  8     for i, arg := range os.Args{
  9         fmt.Println(i, arg)
 10     }
 11 }


输出
[root@localhost GO]# ./hello hello world
3
0 ./hello
1 hello
2 world

猜你喜欢

转载自blog.csdn.net/weixin_42720316/article/details/89180665
今日推荐