What does "write to w" mean?

polaris · · 476 次点击    
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
<p>I&#39;m guessing this is an incredibly basic question - my apologies for asking, but I&#39;m having trouble figuring this out after Googling and going through pages.</p> <p>I see &#34;writes to w&#34; a lot on this official Golang page: <a href="https://golang.org/pkg/fmt/" rel="nofollow">https://golang.org/pkg/fmt/</a></p> <p>Example:</p> <blockquote> <p>Fprint formats using the default formats for its operands and writes to w.</p> </blockquote> <p>What does that mean? Thanks.</p> <hr/>**评论:**<br/><br/>tv64738: <pre><blockquote> <p>func Fprint(<strong>w</strong> io.Writer, a ...interface{}) (n int, err error)</p> <p>Fprint formats using the default formats for its operands and writes to w.</p> </blockquote></pre>_nefario_: <pre><p>w in this case is something that implements the <a href="https://golang.org/pkg/io/#Writer" rel="nofollow">io.Writer interface</a>, so it has a Write method. when they say &#34;write to w&#34;, they mean call the Write method</p></pre>stoned_phillips: <pre><p>Ah, I see. Cool. Thanks!</p></pre>natefinch: <pre><p>Just to clarify further... w is the name of one of the arguments. Go documentation often does this, where it will refer to arguments by name with no other context. Once you get used to it, it&#39;s nice, because it avoids having the javadoc thing where you have to define the argument but then the description is just useless.</p> <p>// @param w the io.Writer to write to</p></pre>de_joerg: <pre><p>Its expecting an instance that have an implemented Writer interface: <code>type Writer interface { Write(p []byte) (n int, err error) }</code></p> <p>An instance will read the stream of p []byte and will write it into a sink, e.g. buffer, terminal, memory.</p></pre>

入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889

476 次点击  
加入收藏 微博
暂无回复
添加一条新回复 (您需要 登录 后才能回复 没有账号 ?)
  • 请尽量让自己的回复能够对别人有帮助
  • 支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`
  • 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
  • 图片支持拖拽、截图粘贴等方式上传