golang fmt.Fprint()格式化字符串写入对象
fmt.Fprint()语法
func fmt.Fprint(w io.Writer, a ...any) (n int, err error)
golang源码对fmt.Fprint()方法的介绍
Fprint formats using the default formats for its operands and writes to w. Spaces are added between operands when neither is a string. It returns the number of bytes written and any write error encountered.
即,golang的fmt标准库中的Fprint()方法,将采用默认格式将其参数格式化,并写入参数w指定的对象中。
fmt.Fprint()参数
参数 | 描述 |
---|---|
w | io.Writer接口对象,如标准输出 os.Stdout和文件 os.File等等 |
a | (个数)可变的参数 |
fmt.Fprint()方法返回值
写入到io.Writer接口对象中的字节数n int,以及可能遇到的错误err error。
fmt.Fprint()方法实例代码
package main
import (
"fmt"
"os"
)
func main() {
name := "笨鸟工具"
host := "x1y1z1.com"
fmt.Fprint(os.Stdout, name, host)
}
运行go文件,得到输出:
笨鸟工具x1y1z1.com
免责声明:内容仅供参考。