Reading an integer from standard input

前端 未结 5 1959
轻奢々
轻奢々 2020-12-12 18:58

How do I use the fmt.Scanf function in Go to get an integer input from the standard input?

If this can\'t be done using fmt.Scanf, what\'s

5条回答
  •  心在旅途
    2020-12-12 19:35

    http://golang.org/pkg/fmt/#Scanf

    All the included libraries in Go are well documented.

    That being said, I believe

    func main() {
        var i int
        _, err := fmt.Scanf("%d", &i)
    }
    

    does the trick

提交回复
热议问题