Golang fmt.Scanln() function example

package fmt

Scanln is similar to Scan, but stops scanning at a newline and after the final item there must be a newline or EOF.

Golang fmt.Scanln() function usage example

 package main

 import (
 "fmt"
 )

 func main() {
 var input string

 fmt.Println("Who will inherit this planet after we are gone ? ")

 fmt.Scanln(&input) //<--- here

 fmt.Println("Your answer : ", input)
 }

Sample output :

Who will inherit this planet after we are gone ?

Alien

Your answer : Alien

Reference :

http://golang.org/pkg/fmt/#Scanln

Advertisement