代碼:reader := bufio.NewReader(os.Stdin)fmt.Print("Enter a number")input,_ := reader.ReadString('\n')fmt.Printf("Type of the entered value is %T\n",input)fmt.Println(input)out,_ := strconv.Atoi(input)fmt.Printf("Type now is: %T\n", out)fmt.Printf("Value now is %d\n",out)fmt.Println(out)Golang 的完全初學者。我試圖解決來自 r/dailyprogrammer 的問題之一。我用代碼片段讀取了來自 SO 的輸入,以及 strconv.Atoi 函數。這個函數的例子很有意義,但是當我將它應用到我從標準輸入讀取的輸入時,它給了我 0。
從 stdin 讀取到 int 的字符串的類型轉換給我一個 0
慕無忌1623718
2023-06-12 11:13:41