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
+10.3k Golang : Embed secret text string into binary(executable) file
+7.6k Android Studio : AlertDialog to get user attention example
+17.1k Golang : Covert map/slice/array to JSON or XML format
+7k Golang : Levenshtein distance example
+20.3k Golang : Check if os.Stdin input data is piped or from terminal
+36.6k Golang : Validate IP address
+30.4k Golang : How to redirect to new page with net/http?
+11.8k Golang : convert(cast) float to string
+7k Golang : How to call function inside template with template.FuncMap
+8.5k PHP : How to parse ElasticSearch JSON ?
+6.4k CodeIgniter : form input set_value cause " to become & quot
+3.4k Golang : Fix go-cron set time not working issue