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
+19.1k Golang : Check whether a network interface is up on your machine
+9.3k Golang : Timeout example
+9.3k Golang : Create unique title slugs example
+17k Golang : Get number of CPU cores
+11k Golang : Read until certain character to break for loop
+15.3k Golang : Find location by IP address and display with Google Map
+12.2k Golang : Get month name from date example
+12.1k Golang : Get remaining text such as id or filename after last segment in URL path
+7.6k Golang : Command line ticker to show work in progress
+5.6k Unix/Linux : How to find out the hard disk size?
+4.7k JavaScript: Add marker function on Google Map
+5.8k Golang : Detect variable or constant type