在Go语言中,fmt.Print()函数将输出写入标准输出(stdout)。

huangapple go评论87阅读模式
英文:

Does fmt.Print() write to stdout in GoLang?

问题

fmt.Print()函数在Go语言中将输出写入标准输出(stdout)。你不需要使用os.Stdout.Write来实现相同的功能。

英文:

I may be overthinking this too much, but in GoLang, does fmt.Print() write to stdout or do I have to use os.Stdout.Write?

答案1

得分: 44

根据文档

> Print使用其操作数的默认格式进行格式化,并写入标准输出。

所以是的,它会写入标准输出(stdout)。

英文:

From the documentation:

> Print formats using the default formats for its operands and writes to standard output.

So yep, it writes to stdout.

答案2

得分: 16

是的,它确实有这个功能。从源代码中可以看到:

// Print formats using the default formats for its operands and writes to standard output.
// Spaces are added between operands when neither is a string.
// It returns the number of bytes written and any write error encountered.
func Print(a ...interface{}) (n int, err error) {
    return Fprint(os.Stdout, a...)
}

os.Stdout 确实代表标准输出流。

英文:

Yes, it does. From the source code:

// Print formats using the default formats for its operands and writes to standard output.
// Spaces are added between operands when neither is a string.
// It returns the number of bytes written and any write error encountered.
func Print(a ...interface{}) (n int, err error) {
	return Fprint(os.Stdout, a...)
}

os.Stdout indeed represents the standard output stream.

答案3

得分: 4

根据Print文档Print使用默认格式对其操作数进行格式化,并将结果写入标准输出。

英文:

From the Print documentation: Print formats using the default formats for its operands and writes to standard output.

huangapple
  • 本文由 发表于 2015年1月20日 05:25:15
  • 转载请务必保留本文链接:https://go.coder-hub.com/28033734.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定