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
+4.6k Python : Find out the variable type and determine the type with simple test
+5.8k Golang : Measure execution time for a function
+9.1k Golang : Web(Javascript) to server-side websocket example
+10.8k Golang : Fix - does not implement sort.Interface (missing Len method)
+10.8k Golang : Web routing/multiplex example
+5.3k Golang : Configure crontab to poll every two minutes 8am to 6pm Monday to Friday
+11.3k Golang : Display a text file line by line with line number example
+30.5k error: trying to remove "yum", which is protected
+16.2k Golang : Delete files by extension
+19.7k Golang : Reset or rewind io.Reader or io.Writer
+9.9k Golang : Random Rune generator
+12.8k Golang : How to calculate the distance between two coordinates using Haversine formula