Skip to content

Instantly share code, notes, and snippets.

@codcodog
Created April 30, 2019 03:45
Show Gist options
  • Save codcodog/fa987b5cd4d8adb34ab540a4419f8957 to your computer and use it in GitHub Desktop.
Save codcodog/fa987b5cd4d8adb34ab540a4419f8957 to your computer and use it in GitHub Desktop.
读取行
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)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment