shad-go/lectures/10-io/scanner/main.go

18 lines
305 B
Go
Raw Normal View History

2020-04-23 01:40:13 +00:00
package main
import (
"bufio"
"fmt"
"os"
)
func main() {
scanner := bufio.NewScanner(os.Stdin)
for scanner.Scan() {
fmt.Println(scanner.Text()) // Println will add back the final '\n'
}
if err := scanner.Err(); err != nil {
_, _ = fmt.Fprintln(os.Stderr, "reading standard input:", err)
}
}