我只想简单地写一个从int转换的字符串。 但f.WriteString而不是数字从ASCII代码表中写入符号。
我预计“noReport = 12320 nr3h = 105 nr2h = 162 nr1h = 38 ok = 16899”
但反而得到了“noReport =〠nr3h= i nr2h =¢nr1h =&ok =䈃”
I just want simply write to file a string converted from int. But f.WriteString instead of number write a symbols from ASCII code table.
I expected "noReport = 12320 nr3h = 105 nr2h = 162 nr1h = 38 ok = 16899"
But instead got "noReport = 〠 nr3h = i nr2h = ¢ nr1h = & ok = 䈃"
最满意答案
https://play.golang.org/p/QAXJ4aJBy3
fmt.Printf("os.StdOut is %T\n", os.Stdout) os.Stdout.WriteString("noReport = 12320 nr3h = 105 nr2h = 162 nr1h = 38 ok = 16899 \n") os.Stdout.WriteString("12320") //Output //os.StdOut is *os.File //noReport = 12320 nr3h = 105 nr2h = 162 nr1h = 38 ok = 16899 //12320对我来说很好。
请给我们你的代码。
UDP
string(noReport),noReport是整数吗? 这是预期的行为。
使用strconv.Itoa (noReport)。
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")或者evanmcdonnal的回答 。
https://play.golang.org/p/QAXJ4aJBy3
fmt.Printf("os.StdOut is %T\n", os.Stdout) os.Stdout.WriteString("noReport = 12320 nr3h = 105 nr2h = 162 nr1h = 38 ok = 16899 \n") os.Stdout.WriteString("12320") //Output //os.StdOut is *os.File //noReport = 12320 nr3h = 105 nr2h = 162 nr1h = 38 ok = 16899 //12320Works fine for me.
Give us your code, please.
UDP
string(noReport), noReport is integer right? Thats expected behavior.
Use strconv.Itoa(noReport).
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")Or evanmcdonnal's answer.
更多推荐
发布评论