C++ 中的中文编码 | SF-Zhou's Blog #179
Replies: 8 comments
-
|
一:26 个小写字母(从 97 开始) 谢谢博主!!! |
Beta Was this translation helpful? Give feedback.
-
感谢指出 typo~ UTF-8 里大部分的汉字需要三个字节来编码的,少数生僻字需要更多的字节。可以用 Python 简单验证: print(len(u'中国人'.encode('utf-8'))) # output 9 |
Beta Was this translation helpful? Give feedback.
-
|
Got it. |
Beta Was this translation helpful? Give feedback.
-
|
你好,我在Windows10下,VS2017里运行了你最后贴出的“最佳实践”代码。得到的test_02.txt文件,用Notepad打开显示乱码(状态栏显示UTF-8)。另存为“ANSI”后再打开,中文显示正确,并且状态栏显示UTF-8。 |
Beta Was this translation helpful? Give feedback.
-
你好。我自己暂时没有 Windows 的测试环境,没法复现你的问题。不过你可以检查下源代码文件本身的编码,看下是不是 UTF-8;然后对于输出的文件,可以使用 16 进制编辑器查看下内容,期望的输出应该是:"e6 88 91 e7 88 b1 43 2b 2b 0a" |
Beta Was this translation helpful? Give feedback.
-
感谢回复。我检查了源代码文件编码,是UTF-8格式。输出文件,我用HxD64.exe查看,内容是
|
Beta Was this translation helpful? Give feedback.
-
测试了一下,VS 比较迷,代码文件需要使用 ANSI 编码才会有期望的输出。所以现在直接在字符串里给了 Unicode 值了,测试就 OK 了。 |
Beta Was this translation helpful? Give feedback.
-
|
hello |
Beta Was this translation helpful? Give feedback.

Uh oh!
There was an error while loading. Please reload this page.
-
https://sf-zhou.github.io/programming/chinese_encoding.html
Beta Was this translation helpful? Give feedback.
All reactions