I wrote simple codes to test println and fmt.Println, but when I ran the code, it printed different results almost everytime. I tried to google the difference between println and fmt.Println but got nothing. Is there any one who knows the real difference or the priority or the sequence of those two function?
Here is the code:
package main
import (
"fmt"
)
func main(){
println("a")
fmt.Println("b")
println("c")
fmt.Println("d")
p()
}
func p(){
println("e")
fmt.Println("f")
println("g")
fmt.Println("h")
}
Thanks!
func println(args ...Type)
The println built-in function formats its arguments in an implementation- specific way and writes the result to standard error. Spaces are always added between arguments and a newline is appended. Println is useful for bootstrapping and debugging; it is not guaranteed to stay in the language.
func Println(a ...interface{}) (n int, err error)
Println formats using the default formats for its operands and writes to standard output. Spaces are always added between operands and a newline is appended. It returns the number of bytes written and any write error encountered.
fmt.Println()
uses stdout
; println()
uses stderr
.
As expected, two different functions with different purposes give different results.