1
package main

import "fmt"

func plus(a int, b int) int {
    return a + b
}
}
func plusPlus(a, b, c int) int {
    return a + b + c
}

func main() {
    res := plus(1, 2)
    fmt.Println("1+2 =", res)

    res = plusPlus(1, 2, 3)
    fmt.Println("1+2+3 =", res)
}

这是我的 Go 源代码。 gofmt -e my_file.go正在工作但我无法将错误写入文本文件。

4

1 回答 1

2

gofmt将错误输出到标准错误。您可以简单地将标准错误流重定向gofmt到 unix 系统上的文件,如下所示:

gofmt -e my_file.go 2>a.txt

检查它:

more a.txt

输出:

my_file.go:8:1: expected declaration, found '}'
于 2018-08-01T06:41:05.650 回答