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
+3.7k Chrome : How to block socketloop.com links in Google SERP?
+7.9k Golang : Write multiple lines or divide string into multiple lines
+8.8k PHP : Get coordinates latitude/longitude from string
+6.3k Golang : Calculate how many weeks left to go in a given year
+19.9k Golang : Convert string slice to struct and access with reflect example
+9.6k Golang : Get currencies exchange rates example
+3.9k Golang : Get a list of crosses(instruments) available to trade from Oanda account
+12.4k Golang : Strings comparison
+11.3k Golang : Validate email address
+4.5k Clean up Visual Studio For Mac installation failed disk full problem
+11.8k Generate salted password with OpenSSL example
+6.1k Ubuntu : connect() to unix:/var/run/php5-fpm.sock failed (13: Permission denied) while connecting to upstream