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
+17k Golang : Find IP address from string
+6k Golang : A simple forex opportunities scanner
+16.5k Golang : How to log each HTTP request to your web server?
+14.8k Golang : Delete files by extension
+5.5k Nginx : Password protect a directory/folder
+8.1k Golang : Create and shuffle deck of cards example
+9.4k Golang : How to delete element(data) from map ?
+8.3k Golang : How to generate Code 39 barcode?
+10.6k Golang : Handle API query by curl with Gorilla Queries example
+6.9k Golang : Configure Apache and NGINX to access your Go service example
+16.8k Golang : Check if a directory exist or not
+8.1k Golang : Play .WAV file from command line