英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论