Golang Printf/Fprintf

이백이·2021년 11월 24일

Golang

목록 보기
3/9

fmt.Printf는 내가 지정한 format으로 같이 입력한 interface를 출력해준다.
fmt.Fprintf는 Printf에 추가로 Writer 버퍼까지 지정할 수 있다고 한다.

var writer = bufio.NewWriter(os.Stdout)
fmt.Fprintf(writer, f, a...)

아래는 print.go에서 가져왔다.

// Fprintf formats according to a format specifier and writes to w.
// It returns the number of bytes written and any write error encountered.
func Fprintf(w io.Writer, format string, a ...interface{}) (n int, err error) {
	p := newPrinter()
	p.doPrintf(format, a)
	n, err = w.Write(p.buf)
	p.free()
	return
}

// Printf formats according to a format specifier and writes to standard output.
// It returns the number of bytes written and any write error encountered.
func Printf(format string, a ...interface{}) (n int, err error) {
	return Fprintf(os.Stdout, format, a...)
}

파이썬만 하던 난 아직 모르겠다.

profile
아직 모른다

0개의 댓글