I recently learned the go language and found that the strings returned after some library functions fail to be called are garbled and strange. So I wrote the simplestProgramTo reproduce this problem:
Func main (){
_, Err: = OS. Open ("None-exist-file ")
If Err! = Nil {
FMT. println (ERR)
}
} Compilation and running are all normal, but the output is garbled: Open none-exist-file: too many characters. Why is the optimized version too many characters? The reason is that the go language outputs in UTF-8 encoding, and the windows Console does not support UTF-8 by default. The solution is to change the code page. Use the command chcp to display the current code page without adding any parameters. Change code page to 65001. In addition, the font should be changed to Lucia console.Such changes may cause garbled characters in other programs that do not use UTF-8 encoding. Some related links:Https://groups.google.com/forum! Topic/golang-Nuts/whpwnhbrmfm/discussion
Https://groups.google.com/group/golang-nuts/browse_thread/thread/cf9727737e5b4a00/d0e9d4dc975e875b? Lnk = GST & Q = messy + code # d0e9d4dc975e875b Http://hi.baidu.com/edeed/blog/item/2e99a14440bd8884b2b7dcb1.html Http://blog.codingnow.com/2008/12/utf-8_replacement.html