package main import ( "os" "text/tabwriter" ) func main() { w := tabwriter.NewWriter(os.Stdout, 0, 0, 1, ' ', tabwriter.AlignRight) defer w.Flush() // write some data to the tab writer fmt.Fprintln(w, "Name\tAge\tLocation") fmt.Fprintln(w, "Ben\t24\tNew York") fmt.Fprintln(w, "Sara\t31\tLos Angeles") fmt.Fprintln(w, "John\t42\tChicago") }
package main import ( "os" "text/tabwriter" ) func main() { w := tabwriter.NewWriter(os.Stdout, 0, 0, 1, ' ', tabwriter.AlignRight) // write some data to the tab writer fmt.Fprintln(w, "Name\tAge\tLocation") fmt.Fprintln(w, "Ben\t24\tNew York") fmt.Fprintln(w, "Sara\t31\tLos Angeles") fmt.Fprintln(w, "John\t42\tChicago") // manually flush the buffer to the underlying writer w.Flush() }This example demonstrates how to manually flush the buffer to the underlying writer using the Flush() method. Package library: text/tabwriter