我知道如果我在vs中使用unicode charset,我可以使用L"There is a string"来表示unicode字符串。 我认为当vs正在进行词法解析时,会从srouce文件中读取There is a string ,它会解码There is a string可以从源文件的编码中解码。
我已将源文件更改为一些不同的编码,但我总是从L marco获得正确的unicode数据。 剂量vs检测源文件的编码以隐藏There is a string来纠正unicode? 如果没有,vs如何实现这一目标?
我不确定是否可以问这个问题,如果没有,我应该问哪里? 提前致谢。
I know if I using unicode charset in vs, I can use L"There is a string" to present an unicode string. I think There is a string will be read from srouce file when vs is doing lexical parsing, it will decode There is a string to unicode from source file's encoding.
I have change source file to some different encodings, but I always got the correct unicode data from L marco. Dose vs detect the encoding of source file to covert There is a string to correct unicode ? If not, how does vs achieve this ?
I'm not sure whether this question could be asked in SO, if not , where should I ask? Thanks in advance.
最满意答案
如果在源文件的开头没有BOM 1签名,VS将不会检测编码。 如果没有BOM,它将假设本地化的ANSI编码。
BOM签名标识所使用的UTF8 / 16/32编码。 因此,如果您将某些内容保存为UTF-8(VS将添加BOM)并删除前3个字节(EF BB BF),则该文件将在美国Windows上解释为CP1252,而在中文Windows上将被解释为GB2312等。
您使用的是中文Windows,因此要么保存为GB2312(无BOM)或UTF8(带BOM),以便正确解码源代码。
1 https://en.wikipedia.org/wiki/Byte_order_mark
VS won't detect the encoding without a BOM1 signature at the start of a source file. It will just assume the localized ANSI encoding if no BOM is present.
A BOM signature identifies the UTF8/16/32 encoding used. So if you save something as UTF-8 (VS will add a BOM) and remove the first 3 bytes (EF BB BF), then the file will be interpreted as CP1252 on US Windows, but GB2312 on Chinese Windows, etc.
You are on Chinese Windows, so either save as GB2312 (without BOM) or UTF8 (with BOM) for VS to decode your source code correctly.
1https://en.wikipedia.org/wiki/Byte_order_mark
更多推荐
vs,unicode,string,电脑培训,计算机培训,IT培训"/> <meta name="description
发布评论