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
+25.4k Golang : How to write CSV data to file
+13.2k Golang : Read from buffered reader until specific number of bytes
+12.6k Golang : http.Get example
+14.2k Golang : Send email with attachment(RFC2822) using Gmail API example
+18.7k Golang : Read input from console line
+8.8k Golang : Handle sub domain with Gin
+7.3k Android Studio : AlertDialog to get user attention example
+7.5k Golang : How to execute code at certain day, hour and minute?
+12.2k Golang : "https://" not allowed in import path
+28.9k Golang : Saving(serializing) and reading file with GOB
+39.7k Golang : Convert to io.ReadSeeker type
+9.4k Golang : Format strings to SEO friendly URL example