Standard library / fmt

fmt.Fprintf()

Writes to the supplied io.Writer rather than stdout. Format-directed output; format must match arguments. Returns byte count and write error. Expected stdout: '"009" 3 <nil>\n'.

Formal Syntax & Structure

go syntaxgo
func Fprintf(w io.Writer, format string, a ...any) (n int, err error)

Parameters & Attributes

NameTypeDescription
wio.WriterDestination implementing io.Writer.
formatstringFormat string containing literal text and formatting or scanning directives.
a...anyValues consumed by formatting; may be empty.

Return Value

(n int, err error)

Number of bytes written and write error.

Working Example

Example Snippetgo
package main
import (  "bytes"  "fmt")
func main() {  var b bytes.Buffer  n, e := fmt.Fprintf(&b, "%03d", 9)  fmt.Printf("%q %d %v\n", b.String(), n, e)}
Go Reference