go helloworld

 

// Sample program to show how a bytes.Buffer can also be used
// with the io.Copy function.
package main

import (
    "bytes"
    "fmt"
    "io"
    "os"
)

// main is the entry point for the application.
func main() {
    var b bytes.Buffer

    // Write a string to the buffer.
    b.Write([]byte("Hello"))

    // Use Fprintf to concatenate a string to the Buffer.
    fmt.Fprintf(&b, " World!\n")

    // Write the content of the Buffer to stdout.
    io.Copy(os.Stdout, &b)
}

输出

Hello World!

 

posted @ 2019-02-09 15:14  anobscureretreat  阅读(190)  评论(0编辑  收藏  举报