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
+8.4k Golang : Find relative luminance or color brightness
+11.3k Golang : Fix go.exe is not compatible with the version of Windows you're running
+5.7k PHP : Fix Call to undefined function curl_init() error
+18.9k Golang : convert int to string
+5.4k Javascript : Change page title to get viewer attention
+13.9k Golang : Qt progress dialog example
+10.5k Golang : Detect number of faces or vehicles in a photo
+8.3k Golang : Multiplexer with net/http and map
+18.8k Golang : Send email with attachment
+12.9k Golang : Sort and reverse sort a slice of bytes
+4.9k JavaScript: Add marker function on Google Map
+20.2k Golang : Convert(cast) bytes.Buffer or bytes.NewBuffer type to io.Reader