golang fmt.Fprintln()
fmt.Fprintln()语法
func fmt.Fprintln(w io.Writer, a ...any) (n int, err error)
golang源码对fmt.Fprintln()方法的介绍
Fprintln formats using the default formats for its operands and writes to w. Spaces are always added between operands and a newline is appended. It returns the number of bytes written and any write error encountered.
即,golang标准库中fmt.Fprintln()使用默认格式将a参数格式化并写入参数w指定的对象中,相邻的参数之间将会添加空格,结束后会在输出的末尾添加一个换行符。
fmt.Fprintln()参数
参数 | 描述 |
---|---|
w | io.Writer接口的对象; |
a | fmt.Println()的可变的参数; |
fmt.Fprintln()方法返回值
格式化输出的字节数n和一切可能遇到的error。
fmt.Fprintln()方法实例代码
package main
import (
"fmt"
"os"
)
func main() {
website_name := "笨鸟工具"
website_host := "x1y1z1.com"
fmt.Fprintln(os.Stdout, website_name, website_host)
}
运行go文件,得到输出:
笨鸟工具 x1y1z1.com
免责声明:内容仅供参考。