dongpi9494 2016-12-30 06:25
浏览 141
已采纳

为什么在使用`log.Println`和`fmt.Println`时改变输出顺序?

Here is my code: package main

import "log"
import "fmt"

func main() {
    var a string = "initail"
    log.Println(a)
    var b, c int = 1, 2
    fmt.Println(b, c)
}

The output is:

1 2
2016/12/30 14:22:58 initail

So i don't understand why the output's order? why log.Println is slower than fmt.Println?

  • 写回答

1条回答 默认 最新

  • dqu94359 2016-12-30 06:42
    关注

    Only difference between those in terms of its printing behaviour is

    • log.Println writes to Stderr
    • fmt.Println writes to Stdout

    Both are not buffered. So the fact that StdOut came before StdError is specific to your terminal or environment.

    Here is a play link https://play.golang.org/p/0cukg_a9GR

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 宇视监控服务器无法登录
  • ¥15 PADS Logic 原理图
  • ¥15 PADS Logic 图标
  • ¥15 电脑和power bi环境都是英文如何将日期层次结构转换成英文
  • ¥20 气象站点数据求取中~
  • ¥15 如何获取APP内弹出的网址链接
  • ¥15 wifi 图标不见了 不知道怎么办 上不了网 变成小地球了
  • ¥50 STM32单片机传感器读取错误
  • ¥50 power BI 从Mysql服务器导入数据,但连接进去后显示表无数据
  • ¥15 (关键词-阻抗匹配,HFSS,RFID标签天线)