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
+13.6k Golang : Increment string example
+6.7k Golang : Convert an executable file into []byte example
+8.4k Golang : Oanda bot with Telegram and RSI example
+22k Golang : Convert string slice to struct and access with reflect example
+36.8k Golang : Save image to PNG, JPEG or GIF format.
+5.9k Linux/Unix/PHP : Restart PHP-FPM
+6.8k Golang : Check if password length meet the requirement
+7.6k Golang : Detect sample rate, channels or latency with PortAudio
+20.5k Golang : How to get own program name during runtime ?
+26k Golang : Daemonizing a simple web server process example
+8.1k Golang : Handle Palindrome string with case sensitivity and unicode
+7k How to let Facebook Login button redirect to a particular URL ?