golang int8如何赋值报错 cannot use int80 constant 0 of type int8 as string value in assignment
在Go语言中,int8类型的值不能直接赋值给字符串类型的变量。如果你想要将int8类型的值转换为字符串,可以使用strconv包中的函数来进行转换。
下面是一个示例代码,演示如何将int8类型的值转换为字符串类型:
package main
import (
"fmt"
"strconv"
)
func main() {
var num int8 = 0
str := strconv.Itoa(int(num))
fmt.Println(str)
}
在上面的示例中,我们使用了strconv.Itoa()函数将int8类型的值转换为字符串类型。在调用该函数之前,我们需要先将int8类型的值转换为int类型,然后再将int类型的值转换为字符串类型。
运行上述代码,将会输出字符串"0"。
原文地址: https://www.cveoy.top/t/topic/h9n6 著作权归作者所有。请勿转载和采集!