我在Tour of Go的解释中有以下内容:
package main
import (
"golang.org/x/tour/wc"
str "strings"
)
func WordCount(s string) map[string]int {
results := make(map[str]int)
words := str.Fields(s)
return map[string]int{"x": 1}
}
//func main() {
// wc.Test(WordCount)
//}
这基于https://tour.golang.org/moretypes/23
我的错误是
tmp/sandbox169629521/main.go:9: use of package str without selector
尝试
results := make(map[str.string]int)
现在失败了
tmp/sandbox424441423/main.go:9: cannot refer to unexported name strings.string
tmp/sandbox424441423/main.go:9: undefined: strings.string
答案 0 :(得分:3)
"串"是一个内置的。你不需要做strings.string: