bufio Scanner
bufio.Scanner reads line by line from any reader.
Example
package main
import (
"bufio"
"fmt"
"strings"
)
func main() {
sc := bufio.NewScanner(strings.NewReader("a\nb\nc"))
n := 0
for sc.Scan() {
n++
fmt.Println(n, sc.Text())
}
}Result
1 a 2 b 3 c
Exercise
Read each line.
for sc.() {}
Quiz Test
These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.