Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Vialiceq opened this issue Jan 11, 2022 · 0 comments
Open

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

Vialiceq opened this issue Jan 11, 2022 · 0 comments

Comments

@Vialiceq
Copy link

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)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant