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
+6k Golang : Takes a plural word and makes it singular
+12.5k Golang : Activate web camera and broadcast out base64 encoded images
+12.4k Golang : Get dimension(width and height) of image file
+6.9k Golang : get the current working directory of a running program
+10k Golang : Read until certain character to break for loop
+14.8k Golang : Update database with GORM example
+14.6k Golang : Convert date format and separator yyyy-mm-dd to dd-mm-yyyy
+4k JQuery : Calling a function inside Jquery(document) block
+8k Golang : How to get username from email address
+5.1k Golang : Extract unicode string from another unicode string example
+4.5k PHP : Fix Call to undefined function curl_init() error
+9.2k Golang : Embed secret text string into binary(executable) file