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
+11.9k Golang : Split strings into command line arguments
+13.5k Golang : Gin framework accept query string by post request example
+7.3k Golang : Detect sample rate, channels or latency with PortAudio
+5.2k Gogland : Datasource explorer
+9.8k Golang : Bcrypting password
+12.8k Golang : Calculate elapsed years or months since a date
+16.9k Golang : How to tell if a file is compressed either gzip or zip ?
+5.5k Fix yum-complete-transaction error
+10.8k Golang : Create S3 bucket with official aws-sdk-go package
+21.7k Golang : Convert seconds to minutes and remainder seconds
+18.2k Golang : Send email with attachment
+4.6k Javascript : How to get width and height of a div?