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
+6.4k Golang : Take screen shot of browser with JQuery example
+38.8k Golang : Encode image to base64 example
+6.4k Golang : Quadratic example
+6.5k Golang : How to control fmt or log print format?
+7.1k Golang : Underscore string example
+3.5k Golang : Launching your executable inside a console under Linux
+21.3k PHP : Count number of JSON items/objects
+12k Golang : Get IP addresses of a domain name
+14.4k Golang : Generate MD5 checksum of a file
+2.9k Which content-type(MIME type) to use for JSON data
+8.8k Golang : Skip blank/empty lines in CSV file and trim whitespaces example
+35.8k Golang : Disable security check for HTTPS(SSL) with bad or expired certificate