1. 程式人生 > >GoLang 捕獲命令列引數

GoLang 捕獲命令列引數

package main

import (
	"flag"
	"fmt"
)

func main() {
	var (
		s1_string string
		i1_int    int
		i64_1_int int64
	)
	s_string := flag.String("s", "0", "this is s") //返回 string 指標
	flag.StringVar(&s1_string, "s1", "0", "this is s1")

	i_int := flag.Int("i", 0, "this is i") //返回 int 指標
	flag.IntVar(&i1_int, "i1", 0, "this is i1")

	i64_int := flag.Int64("i64", 0, "this is i64") // 返回 int64 指標
	flag.Int64Var(&i64_1_int, "i64", 0, "this is i64_1_int")
	flag.Parse() //解析註冊的flag

	fmt.Println(*s_string)
	fmt.Println(s1_string)

	fmt.Println(*i_int) //int
	fmt.Println(i1_int)

	fmt.Println(*i64_int)
	fmt.Println(i64_1_int)

}