我爱占星网 我爱占星网
首页
编程
java
php
前端
首页 编程 java php 前端

惯用的缓冲os.Stdout

os.Stdout.Write() is an unbuffered write. To get a buffered write, one can use the following:

f := bufio.NewWriter(os.Stdout)
f.Write(b)

Question:

Is there a more idiomatic way to get buffered output?

No, that is the most idiomatic way to buffer writes to Stdout. In many cases, you will want to do also add a defer:

f := bufio.NewWriter(os.Stdout)
defer f.Flush()
f.Write(b)

This will ensure that the buffer is flushed when you return from the function.

近期文章

  • 在Go中,如何将函数的标准输出捕获到字符串中?
  • 在Go中更新日志文件时读取它们
  • 在golang中将数组作为参数传递
  • 在Go中循环两个变量
  • 从根目录提供主页和静态内容
  • Golang依赖性管理最佳实践
  • 如何使用Golang在SQL中执行IN查找?
  • Go如何进行字符串比较?
  • Golang的嵌套地图
  • 如何使用cgo静态链接go中的c库?
  • Golang:测试和工作目录
  • Go中的命令行标记可以设置为强制性吗?
  • 使用数组指针
  • 从Go中的另一个包调用函数
  • 在实践中,传递消息的并发语言比共享内存的并发语言如何更好
  • new()和“常规”分配之间有区别吗?
  • 如何获取Golang其他时区的当前时间戳?
  • 获得无效的操作:尝试为地图建立索引时,mymap [“标题”](类型接口{}不支持索引)
  • 将字符串指针转到字符串
  • 在Go中使用defer

Copyright ©2022 我爱占星 All Rights Reserved.

浙ICP备2022030071号-1

部分图文来自网络,如有侵犯您的版权,请告诉我们删除

友情链接:代码精华