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
+33.2k Golang : How to check if a date is within certain range?
+10.6k Golang : Simple Jawi(Yawi) to Rumi(Latin/Romanize) converter
+12.6k Golang : Flush and close file created by os.Create and bufio.NewWriter example
+5.9k Get website traffic ranking with Similar Web or Alexa
+9.6k Golang : Play .WAV file from command line
+7k Golang : Experimental emojis or emoticons icons programming language
+14.1k Golang : Get dimension(width and height) of image file
+9.8k Golang : Populate slice with sequential integers example
+8.6k Golang : Ackermann function example
+21.7k Curl usage examples with Golang
+27.6k Golang : Convert CSV data to JSON format and save to file