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.9k Golang : Calculate Relative Strength Index(RSI) example
+14.8k Golang : Save(pipe) HTTP response into a file
+29.1k Golang : How to create new XML file ?
+4.7k Golang : Calculate a pip value and distance to target profit example
+6.2k Golang : Handling image beyond OpenCV video capture boundary
+4.5k Adding Skype actions such as call and chat into web page examples
+21.9k Golang : Print leading(padding) zero or spaces in fmt.Printf?
+17.5k Golang : How to make a file read only and set it to writable again?
+7.3k Golang : Dealing with struct's private part
+22.3k Golang : Set and Get HTTP request headers example
+7.9k Golang : Routes multiplexer routing example with regular expression control
+5.7k Unix/Linux : How to open tar.gz file ?