mirror of
https://github.com/unknwon/the-way-to-go_ZH_CN.git
synced 2025-08-12 01:55:35 +08:00
update book code
This commit is contained in:
22
eBook/examples/chapter_12/readinput2.go
Normal file
22
eBook/examples/chapter_12/readinput2.go
Normal file
@@ -0,0 +1,22 @@
|
||||
// read input from the console:
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"bufio"
|
||||
"os"
|
||||
)
|
||||
|
||||
var inputReader *bufio.Reader
|
||||
var input string
|
||||
var err error
|
||||
|
||||
func main() {
|
||||
inputReader = bufio.NewReader(os.Stdin) // reader for input
|
||||
fmt.Println("Please enter some input: ")
|
||||
input, err = inputReader.ReadString('\n')
|
||||
|
||||
if err == nil {
|
||||
fmt.Printf("The input was: %s\n", input)
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user