0
点赞
收藏
分享

微信扫一扫

cannot use lens (type int) as type string in argument to fmt.Printf

搬砖的小木匠 2022-03-11 阅读 130

自学go语言中遇到的一个奇葩问题,printf不能直接输出一个参数,以下就是错误的:

name := “hello,go大法好”
fmt.Printf("\n")
lens := utf8.RuneCountInString(name)
fmt.Printf(lens)

正确写法如下:
name := “hello,go大法好”
fmt.Printf("\n")
lens := utf8.RuneCountInString(name)
fmt.Printf(“字符串长度%d”,lens)
或者直接用println输出也可

举报

相关推荐

0 条评论