Skip to content

Commit 579768e

Browse files
mfrwkevinburke
authored andcommitted
fmt: add example for Fscanln
Updates #27376. Change-Id: I9f33233f1aafa10941a63fcb4e49d351ea7ee246 Reviewed-on: https://go-review.googlesource.com/132675 Reviewed-by: Kevin Burke <[email protected]> Run-TryBot: Kevin Burke <[email protected]> TryBot-Result: Gobot Gobot <[email protected]>
1 parent 4d01f92 commit 579768e

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

src/fmt/example_test.go

+23
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ package fmt_test
66

77
import (
88
"fmt"
9+
"io"
910
"os"
1011
"strings"
1112
)
@@ -77,3 +78,25 @@ func ExampleFprintln() {
7778
// there are 99 gophers
7879
// 21
7980
}
81+
82+
func ExampleFscanln() {
83+
s := `dmr 1771 1.61803398875
84+
ken 271828 3.14159`
85+
r := strings.NewReader(s)
86+
var a string
87+
var b int
88+
var c float64
89+
for {
90+
n, err := fmt.Fscanln(r, &a, &b, &c)
91+
if err == io.EOF {
92+
break
93+
}
94+
if err != nil {
95+
panic(err)
96+
}
97+
fmt.Printf("%d: %s, %d, %f\n", n, a, b, c)
98+
}
99+
// Output:
100+
// 3: dmr, 1771, 1.618034
101+
// 3: ken, 271828, 3.141590
102+
}

0 commit comments

Comments
 (0)