1
0
mirror of https://github.com/golang/go synced 2024-11-23 11:00:08 -07:00

fmt: add example for Fscanln

Updates golang/go#27376.

Change-Id: I9f33233f1aafa10941a63fcb4e49d351ea7ee246
Reviewed-on: https://go-review.googlesource.com/132675
Reviewed-by: Kevin Burke <kev@inburke.com>
Run-TryBot: Kevin Burke <kev@inburke.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
This commit is contained in:
Muhammad Falak R Wani 2018-08-31 23:48:15 +05:30 committed by Kevin Burke
parent 4d01f9243c
commit 579768e078

View File

@ -6,6 +6,7 @@ package fmt_test
import (
"fmt"
"io"
"os"
"strings"
)
@ -77,3 +78,25 @@ func ExampleFprintln() {
// there are 99 gophers
// 21
}
func ExampleFscanln() {
s := `dmr 1771 1.61803398875
ken 271828 3.14159`
r := strings.NewReader(s)
var a string
var b int
var c float64
for {
n, err := fmt.Fscanln(r, &a, &b, &c)
if err == io.EOF {
break
}
if err != nil {
panic(err)
}
fmt.Printf("%d: %s, %d, %f\n", n, a, b, c)
}
// Output:
// 3: dmr, 1771, 1.618034
// 3: ken, 271828, 3.141590
}