這聽起來可能很愚蠢,但是如何在Go中定義全局變量?const myglobalvariable = "Hi there!"真的不起作用...我只想獲取命令行參數(shù),然后我要打印它。我使用以下代碼段執(zhí)行此操作:package mainimport ( "flag" "fmt")func main() { gettext(); fmt.Println(text)}func gettext() { flag.Parse() text := flag.Args() if len(text) < 1 { fmt.Println("Please give me some text!") }}問題是它只是打印一個空行,所以我考慮過使用聲明一個全局變量,const myglobalvariable = "Hi there!"但我只是得到了錯誤cannot use flag.Args() (type []string) as type ideal string in assignment……我知道這是一個菜鳥問題,所以希望您能為我提供幫助...
全局變量/獲取命令行參數(shù)并打印
慕田峪9158850
2021-05-07 18:00:16