Standard library / bytes
bytes.Buffer.WriteString()
Appends string bytes; returns byte count and nil error, or panics if growth fails. Expected stdout: '2 <nil> go\n'.
Formal Syntax & Structure
go syntaxgo
func (b *Buffer) WriteString(s string) (n int, err error)Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| s | string | Data to append or write. |
Return Value
(n int, err error)
Appends string bytes; returns byte count and nil error, or panics if growth fails.
Working Example
Example Snippetgo
package main
import ( "bytes" "fmt")
func main() { var b bytes.Buffer n, e := b.WriteString("go") fmt.Println(n, e, b.String())}