代碼: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 的完全初學(xué)者。我試圖解決來(lái)自 r/dailyprogrammer 的問題之一。我用代碼片段讀取了來(lái)自 SO 的輸入,以及 strconv.Atoi 函數(shù)。這個(gè)函數(shù)的例子很有意義,但是當(dāng)我將它應(yīng)用到我從標(biāo)準(zhǔn)輸入讀取的輸入時(shí),它給了我 0。
從 stdin 讀取到 int 的字符串的類型轉(zhuǎn)換給我一個(gè) 0
慕無(wú)忌1623718
2023-06-12 11:13:41