GO中的Flag包和指针相关
方式一
package main
import (
"flag"
"fmt"
)
func main() {
var name =new(string)// [1]
flag.StringVar(name, "name", "everyone", "The greeting object.") // [2]
flag.Parse()
fmt.Printf("Hello, %v!\n", *name)
}
版本二
package main
import (
"flag"
"fmt"
)
func main() {
var name string// [1]
flag.StringVar(&name, "name", "everyone", "The greeting object.") // [2]
flag.Parse()
fmt.Printf("Hello, %v!\n", name)
}
方式三
package main
import (
"flag"
"fmt"
)
func main() {
var name *string// [1]
flag.StringVar(name, "name", "everyone", "The greeting object.") // [2]
flag.Parse()
fmt.Printf("Hello, %v!\n", name)
}
报错