小编Mud*_*Jha的帖子

从 stdin 读取的字符串到 int 的类型转换给了我一个 0

代码:

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)
Run Code Online (Sandbox Code Playgroud)

Golang 的完全初学者。我试图解决 r/dailyprogrammer 的问题之一。我使用代码片段读取 SO 的输入以及 strconv.Atoi 函数。该函数的示例很有意义,但是当我将其应用于从 stdin 读取的输入时,它给了我 0。

stdin go

1
推荐指数
1
解决办法
955
查看次数

标签 统计

go ×1

stdin ×1