Go语言学习之main包的讲解

### Go语言学习之main包的讲解

1.Go中main函数不支持任何返回值
2.可以通过os.Exit(0)来返回状态

func main(){
    fmt.Println("hellow world")
    os.Exit(0)
}

3.main函数不支持传入参数
4.在程序中可通过os.Args来获取命令行参数

func main(){
    if len(os.Args) > 1{     //判断命令行参数数组长度是否大于1,输出命令行参数
        fmt.Println(os.Args[1])
    }
    fmt.Println("hellow world")
}
//执行
go run main.go alisleepy
//最终结果
alisleepy  hellow world

猜你喜欢

转载自www.cnblogs.com/alisleepy/p/11200312.html
今日推荐