HiveBrain v1.2.0
Get Started
← Back to all entries
patterngoCritical

Reading an integer from standard input

Submitted by: @import:stackoverflow-api··
0
Viewed 0 times
inputreadingfromstandardinteger

Problem

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 the best way to read a single integer?

Solution

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

Code Snippets

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

Context

Stack Overflow Q#3751429, score: 152

Revisions (0)

No revisions yet.