Skip to content

Commit 4d01f92

Browse files
venilnoronhadsnet
authored andcommitted
fmt: add example for Fscanf
Change-Id: Ia3dcb3a82e452fdcf0d087e8cd01ac01ca831c84 Reviewed-on: https://go-review.googlesource.com/132597 Reviewed-by: Joe Tsai <[email protected]> Reviewed-by: Kevin Burke <[email protected]> Run-TryBot: Joe Tsai <[email protected]>
1 parent 88206b8 commit 4d01f92

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

src/fmt/example_test.go

+19
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ package fmt_test
77
import (
88
"fmt"
99
"os"
10+
"strings"
1011
)
1112

1213
// The Errorf function lets us use formatting features
@@ -18,6 +19,24 @@ func ExampleErrorf() {
1819
// Output: user "bueller" (id 17) not found
1920
}
2021

22+
func ExampleFscanf() {
23+
var (
24+
i int
25+
b bool
26+
s string
27+
)
28+
r := strings.NewReader("5 true gophers")
29+
n, err := fmt.Fscanf(r, "%d %t %s", &i, &b, &s)
30+
if err != nil {
31+
panic(err)
32+
}
33+
fmt.Println(i, b, s)
34+
fmt.Println(n)
35+
// Output:
36+
// 5 true gophers
37+
// 3
38+
}
39+
2140
func ExampleSprintf() {
2241
i := 30
2342
s := "Aug"

0 commit comments

Comments
 (0)