Go 写入文件int转换为字符串

Go 写入文件int转换为字符串,go,file-writing,Go,File Writing,我只想简单地写一个从int转换过来的字符串到文件中。但是f.WriteString代替number从ASCII代码表中写一个符号 我期望“noReport=12320 nr3h=105 nr2h=162 nr1h=38 ok=16899” 但却得到了“noReport=〠nr3h=i nr2h=、nr1h=&ok=䈃" 对我来说很好 请给我们你的密码 UDP 字符串(noReport),noReport是整数,对吗?这是预期的行为 使用(noReport) 或者evanmcdonnal的。要获

我只想简单地写一个从int转换过来的字符串到文件中。但是f.WriteString代替number从ASCII代码表中写一个符号

我期望“noReport=12320 nr3h=105 nr2h=162 nr1h=38 ok=16899”

但却得到了“noReport=〠nr3h=i nr2h=、nr1h=&ok=䈃"

对我来说很好

请给我们你的密码

UDP

字符串(noReport),noReport是整数,对吗?这是预期的行为

使用(noReport)


或者evanmcdonnal的。

要获得包含INT的字符串,我建议使用
fmt.Sprintf

大概是这样的,

s := fmt.Sprintf("noReport = %d nr3h = %d nr2h = %d nr1h = %d ok = 16899", 12320, 162, 38)

它将把值
“noReport=12320 nr3h=105 nr2h=162 nr1h=38 ok=16899”
分配给
s
noReport := 12320 nr3h := 105 nr2h := 162 nr1h := 38 ok := 16899 os.Stdout.WriteString("noReport = "+ strconv.Itoa(noReport) + " nr3h = " + strconv.Itoa(nr3h)+ " nr2h = "+ strconv.Itoa(nr2h)+ " nr1h = "+ strconv.Itoa(nr1h) + " ok = "+ strconv.Itoa(ok)+ "\n")
s := fmt.Sprintf("noReport = %d nr3h = %d nr2h = %d nr1h = %d ok = 16899", 12320, 162, 38)