Standard library / io

io.StringWriter

Optional string-write interface; io.WriteString uses it when available. Expected stdout: '2 <nil>\n'.

Formal Syntax & Structure

go syntaxgo
type StringWriter interface {  WriteString(s string) (n int, err error)}

Working Example

Example Snippetgo
package main
import (  "bytes"  "fmt"  "io")
func main() {  var b bytes.Buffer  var w io.StringWriter = &b  n, e := w.WriteString("ok")  fmt.Println(n, e)}
Go Reference