package main
import "fmt"
import "os"
func main() {
// 接受用户传递的参数,都是以字符串方式传递
list := os.Args
n := len(list)
fmt.Println("n = ", n)
for i := 0; i < n; i++ {
fmt.Printf("list[%d] = %s\n", i, list[i])
}
}
//结果
n = 5
list[0] = C:\Users\mz\AppData\Local\Temp\go-build130826698\b001\exe\07_获取命令行参数.exe
list[1] = ci
list[2] = dke
list[3] = dfs
list[4] = cdgd
网友评论