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
+12.6k Golang : Forwarding a local port to a remote server example
+13.3k Golang : Convert(cast) int to int64
+19.8k Golang : Get current URL example
+19.5k Golang : Fix cannot download, $GOPATH not set error
+31.8k Golang : Get local IP and MAC address
+8k Javascript : Put image into Chrome browser's console
+24.2k Golang : Find biggest/largest number in array
+10.5k Golang : Meaning of omitempty in struct's field tag
+12.3k Golang : md5 hash of a string
+14.6k Golang : Rename directory
+9.1k Golang : Build and compile multiple source files
+8.1k Golang : Trim everything onward after a word