1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
| package main
import ( "fmt" "os" )
type point struct { x, y int }
func main() { str := "print" fmt.Printf("%s\n", str) // "string" use a format fmt.Print(str) // "string" not add a newline fmt.Println(str, 1, 2) // "string 1 2" add a newline
str = "sprint" sprintStr := fmt.Sprintf("%s\n", str) // "sprint" use a foamat fmt.Print(sprintStr)
sprintStr = fmt.Sprint(str) // not add a new line fmt.Print(sprintStr)
sprintStr = fmt.Sprintln(str) // add a new line fmt.Print(sprintStr)
str = "fprint" fmt.Fprintf(os.Stdout, "%s\n", str) fmt.Fprint(os.Stdout, str) fmt.Fprintln(os.Stdout, str) }
|