diff options
author | Venil Noronha <veniln@vmware.com> | 2018-08-31 10:11:22 -0700 |
---|---|---|
committer | Joe Tsai <thebrokentoaster@gmail.com> | 2018-08-31 18:27:09 +0000 |
commit | 4d01f9243c6dfcd82993483063421fc8aceeb353 (patch) | |
tree | 225a8865f94e722c3da408a4b6310526a4ef7003 /src/fmt | |
parent | 88206b89313bd7c143bc0d4946543969255ecc2b (diff) | |
download | go-4d01f9243c6dfcd82993483063421fc8aceeb353.tar.gz go-4d01f9243c6dfcd82993483063421fc8aceeb353.zip |
fmt: add example for Fscanf
Change-Id: Ia3dcb3a82e452fdcf0d087e8cd01ac01ca831c84
Reviewed-on: https://go-review.googlesource.com/132597
Reviewed-by: Joe Tsai <thebrokentoaster@gmail.com>
Reviewed-by: Kevin Burke <kev@inburke.com>
Run-TryBot: Joe Tsai <thebrokentoaster@gmail.com>
Diffstat (limited to 'src/fmt')
-rw-r--r-- | src/fmt/example_test.go | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/src/fmt/example_test.go b/src/fmt/example_test.go index 1d2cc0d757..9b72d7a383 100644 --- a/src/fmt/example_test.go +++ b/src/fmt/example_test.go @@ -7,6 +7,7 @@ package fmt_test import ( "fmt" "os" + "strings" ) // The Errorf function lets us use formatting features @@ -18,6 +19,24 @@ func ExampleErrorf() { // Output: user "bueller" (id 17) not found } +func ExampleFscanf() { + var ( + i int + b bool + s string + ) + r := strings.NewReader("5 true gophers") + n, err := fmt.Fscanf(r, "%d %t %s", &i, &b, &s) + if err != nil { + panic(err) + } + fmt.Println(i, b, s) + fmt.Println(n) + // Output: + // 5 true gophers + // 3 +} + func ExampleSprintf() { i := 30 s := "Aug" |