Peng Yu
unread,Jan 18, 2018, 6:05:19 PM1/18/18Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Sign in to report message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to golang-nuts
Hi,
The following example shows how to write a byte slice to a buffer. But
what if I want only write a length shorter (say 2 instead of 5) than
the size of the slice. Is there a function that allows users to
specify the length to write? Thanks.
$ cat main.go
#!/usr/bin/env gorun
// vim: set noexpandtab tabstop=2:
package main
import (
"os"
"bufio"
"fmt"
)
func main() {
f := bufio.NewWriter(os.Stdout)
d := []byte{'s', 'o', 'm', 'e', '\n'}
n, err := f.Write(d)
f.Flush()
fmt.Printf("wrote %d bytes, error %q\n", n, err)
}
--
Regards,
Peng