Golang : How to read integer value from standard input ?
Reading integer value from standard input in Golang is fairly simple with fmt.Scanf function. The code below demonstrate how to capture integer value from the standard input.
package main
import (
"fmt"
)
func main() {
var i int
fmt.Println("Enter an integer value : ")
_, err := fmt.Scanf("%d", &i)
if err != nil {
fmt.Println(err)
}
fmt.Println("You have entered : ", i)
}
See also : Golang : How to read float value from standard input ?
By Adam Ng
IF you gain some knowledge or the information here solved your programming problem. Please consider donating to the less fortunate or some charities that you like. Apart from donation, planting trees, volunteering or reducing your carbon footprint will be great too.
Advertisement
Tutorials
+13.7k Chrome : ERR_INSECURE_RESPONSE and allow Chrome browser to load insecure content
+8.2k Golang : Fix go.exe is not compatible with the version of Windows you're running
+29.2k Golang : Regular Expression for alphanumeric and underscore
+2.3k Java : Random alphabets, alpha-numeric or numbers only string generator
+5.9k Golang : Convert(cast) io.Reader type to string
+10.3k Golang : Convert int(year) to time.Time type
+13.4k Golang : How do I get the local IP (non-loopback) address ?
+27.5k Get client IP Address in Go
+5.8k Golang : Command line ticker to show work in progress
+5.3k Golang : How to iterate a slice without using for loop?
+7.2k Golang : HTTP Routing with Goji example
+3.2k Nginx and PageSpeed build from source CentOS example