golang 库函数 fmt.Fprintf

https://www.geeksforgeeks.org/fmt-fprintf-function-in-golang-with-examples/

在 Go 语言中,fmt 包使用类似于 C 的 printf() 和 scanf() 函数的函数实现格式化的 I/O。 Go 语言中的 fmt.Fprintf() 函数根据格式说明符格式化并写入 w。 而且,这个函数是在 fmt 包下定义的。 在这里,您需要导入“fmt”包才能使用这些功能。

In Go language, fmt package implements formatted I/O with functions analogous to C’s printf() and scanf() function. The fmt.Fprintf() function in Go language formats according to a format specifier and writes to w. Moreover, this function is defined under the fmt package. Here, you need to import the “fmt” package in order to use these functions.

// Golang program to illustrate the usage of
// fmt.Fprintf() function

// Including the main package
package main

// Importing fmt and os
import (
	"fmt"
	"os"
)

// Calling main
func main() {

	// Declaring some const variables
	const name, dept = "GeeksforGeeks", "CS"

	// Calling Fprintf() function which returns
	// "n" as the number of bytes written and
	// "err" as any error ancountered
	n, err := fmt.Fprintf(os.Stdout, "%s is a %s portal.\n",
												name, dept)

	// Printing the number of bytes written
	fmt.Print(n, " bytes written.\n")

	// Printing if any error encountered
	fmt.Print(err)

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值