Skip to content

#os包和flag包获取命令行参数对比 -> 这部分勘误 #2

Description

@Vialiceq

os包和flag包获取命令行参数对比
通过os包获取命令行参数
如果用户没有传递参数会报错
需要严格按照代码中的顺序传递参数, 否则会造成数据混乱
不能指定参数的名称
获取到的数据都是字符串类型

这里的 int main() 要换成 func main() 不然编译通不过


package main
import (
	"os"
	"fmt"
)
// 下面这个 int main( )要换成 func main ( )     ************************************    
int main(){
	name := os.Args[1]
	age := os.Args[2]
	fmt.Println("name = ", name)
	fmt.Println("age = ", age)
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions