package main import ( "bytes" "fmt" ) func main() { var buf bytes.Buffer r := '☃' buf.WriteRune(r) fmt.Println(buf.String()) }
☃
package main import ( "bytes" "fmt" ) func main() { var buf bytes.Buffer runes := []rune{'H', 'e', 'l', 'l', 'o'} for _, r := range runes { buf.WriteRune(r) } fmt.Println(buf.String()) }
HelloIn both examples, the bytes.Buffer package has been imported and a new buffer variable `buf` is created to hold the bytes. In the first example, the rune `☃` (a snowman) is written to the buffer using the WriteRune method and then the buffer content is printed. The output shows the UTF-8 encoding of the snowman. In the second example, an array of runes is defined and iterated over, writing each rune to the buffer using the WriteRune method. The resulting buffer content, which is the string `Hello`, is printed. Therefore, the package library used in these examples is `bytes`.