GO語言"fmt"包中"Fprintf"函數的用法及代碼示例。
用法:
func Fprintf(w io.Writer, format string, a ...any)(n int, err error)
Fprintf 根據格式說明符格式化並寫入 w。它返回寫入的字節數和遇到的任何寫入錯誤。
例子:
package main
import (
"fmt"
"os"
)
func main() {
const name, age = "Kim", 22
n, err := fmt.Fprintf(os.Stdout, "%s is %d years old.\n", name, age)
// The n and err return values from Fprintf are
// those returned by the underlying io.Writer.
if err != nil {
fmt.Fprintf(os.Stderr, "Fprintf: %v\n", err)
}
fmt.Printf("%d bytes written.\n", n)
}
輸出:
Kim is 22 years old. 21 bytes written.
相關用法
- GO Fprintln用法及代碼示例
- GO Fprint用法及代碼示例
- GO Fscanln用法及代碼示例
- GO Float.SetString用法及代碼示例
- GO FileServer用法及代碼示例
- GO FieldsFunc用法及代碼示例
- GO FormatMediaType用法及代碼示例
- GO Float64s用法及代碼示例
- GO Floor用法及代碼示例
- GO FormatUint用法及代碼示例
- GO FormatBool用法及代碼示例
- GO Float64sAreSorted用法及代碼示例
- GO Float.Scan用法及代碼示例
- GO FormatFloat用法及代碼示例
- GO FileMode用法及代碼示例
- GO FullRune用法及代碼示例
- GO FullRuneInString用法及代碼示例
- GO Float.Add用法及代碼示例
- GO Func用法及代碼示例
- GO Frames用法及代碼示例
注:本文由純淨天空篩選整理自golang.google.cn大神的英文原創作品 Fprintf。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。