5.2 标准输出和错误输出


package main

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

func main() {

	// Simply write string
	io.WriteString(os.Stdout,
		"This is string to standard output.\n")

	io.WriteString(os.Stderr,
		"This is string to standard error output.\n")

	// Stdout/err implements
	// writer interface
	buf := []byte{0xAF, 0xFF, 0xFE}
	for i := 0; i < 20; i++ {
		if _, e := os.Stdout.Write(buf); e != nil {
			panic(e)
		}
	}

	// The fmt package
	// could be used too
	fmt.Fprintln(os.Stdout, "\n")
}

/*
This is string to standard error output.
This is string to standard output.
������������������������������������������������������������
*/

posted @ 2018-03-22 00:45  cucy_to  阅读(130)  评论(0)    收藏  举报