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
+12.4k Golang : Query string with space symbol %20 in between
+9.1k Fix ERROR 1045 (28000): Access denied for user 'root'@'ip-address' (using password: YES)
+4.5k Swift : Convert string array to array example
+9k CodeIgniter : Load different view for mobile devices
+4.8k Unix/Linux : Get reboot history or check when was the last reboot date
+13.5k Golang : Rename directory
+13.8k Golang : Basic authentication with .htpasswd file
+12.1k Golang : error parsing regexp: invalid or unsupported Perl syntax
+6.5k Golang : Individual and total number of words counter example
+10.6k Golang : Convert decimal number(integer) to IPv4 address
+6k Golang : Get environment variable