-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy path12_string_writer.go
More file actions
44 lines (37 loc) · 1012 Bytes
/
12_string_writer.go
File metadata and controls
44 lines (37 loc) · 1012 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// Seriál "Programovací jazyk Go"
// https://www.root.cz/serialy/programovaci-jazyk-go/
//
// Dvacátá třetí část
// Pokročilejší použití vstupně-výstupních funkcí standardní knihovny jazyka Go
// https://www.root.cz/clanky/pokrocilejsi-pouziti-vstupne-vystupnich-funkci-standardni-knihovny-jazyka-go/
//
// Repositář:
// https://github.com/tisnik/go-root/
//
// Seznam demonstračních příkladů z dvacáté třetí části:
// https://github.com/tisnik/go-root/blob/master/article_23/README.md
//
// Demonstrační příklad číslo 12:
// Zápis řetězců (StringWriter).
package main
import (
"fmt"
"log"
"os"
)
const filename = "test_output.txt"
const message = "Hello world!"
func main() {
writer, err := os.Create(filename)
if err != nil {
log.Fatal(err)
}
defer writer.Close()
written, err := writer.WriteString(message)
if written > 0 {
fmt.Printf("written %d bytes\n", written)
}
if err != nil {
fmt.Printf("I/O error %v\n", err)
}
}