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
+5.6k Golang : Markov chains to predict probability of next state example
+30.2k Golang : Generate random string
+14.2k Golang : On enumeration
+10.3k Golang : Allow Cross-Origin Resource Sharing request
+7.4k Golang : Convert(cast) io.Reader type to string
+16.3k Golang : Generate QR codes for Google Authenticator App and fix "Cannot interpret QR code" error
+5.3k How to check with curl if my website or the asset is gzipped ?
+32.7k Golang : How to check if a date is within certain range?
+5.4k PHP : Convert CSV to JSON with YQL example
+10.3k Android Studio : Simple input textbox and intercept key example
+11.5k Golang : convert(cast) float to string
+14.1k Golang : How to convert a number to words