The file contains a character that cannot be represented in the current code page (936)

37 篇文章 0 订阅

1. 方法一:将文件中的乱码找到去掉

//z 2012-07-06 10:22:32 AM IS2120@CSDN.T113491669

用VS2005+DirectX9 SDK(手头测试过的是2004年10月的DirectX SDK和2006年4月的DirectX SDK)编译游戏会出现以下warning:

--------------------------------------------------------------------------------

d:\microsoft directx 9.0 sdk (october 2004)\include\d3d9types.h(1385) : warning C4819: The file contains a character that cannot be represented in the current code page (936). Save the file in Unicode format to prevent data loss

--------------------------------------------------------------------------------
要修正这个问题,不必要存为UTF8的文件,而是搜索_D3DDEVINFO_VCACHE,然后会看到:

typedef struct _D3DDEVINFO_VCACHE ...{
    DWORD   Pattern;                    /**//* bit pattern, return value must be FOUR_CC(慍? 慉? 慍? 慔? */
    DWORD   OptMethod;                  /**//* optimization method 0 means longest strips, 1 means vertex cache based */
    DWORD   CacheSize;                  /**//* cache size to optimize for  (only required if type is 1) */
    DWORD   MagicNumber;                /**//* used to determine when to restart strips (only required if type is 1)*/
} D3DDEVINFO_VCACHE, *LPD3DDEVINFO_VCACHE;
那四个乱码的去掉就可以了


2.方法二: 将该文件存为 UTF-8 文件

(折腾了很久,记录一下,T113491669)


3. 与此相关的其他信息

其实这是个警告,你可以修改编译选项,不要把警告看做error!
这虽然只是一个警告,但是会导致不能进行DEBUG,断点处无法停止。


To get rid of the second warning(C4819) you need to save the file in Unicode format.

Go to file->advanced save options and under that select the new encoding you want to save it as. UTF-8 or UNICODE codepage 1200 are the settings you want.



11 down vote accepted

Encoding in C++ is quite a bit complicated. Here is my understanding of it.

Every implementation has to support characters from the basic source character set. These include common characters listed in2.2/1. These characters should all fit into onechar. In addition implementations have to support a way to name other characters using a way calleduniversal character names and look like\uffff or \Uffffffff and can be used to refer to unicode characters. A subset of them are usable in identifiers (listed in Annex E).

This is all nice, but the mapping from characters in the file, to source characters (used at compile time) is implementation defined. This constitutes the encoding used. Here is what it says literally:

Physical source file characters are mapped, in an implementation-defined manner, to the basic source character set (introducing new-line characters for end-of-line indicators) if necessary. Trigraph sequences (2.3) are replaced by corresponding single-character internal representations. Any source file character not in the basic source character set (2.2) is replaced by the universal-character-name that des- ignates that character. (An implementation may use any internal encoding, so long as an actual extended character encountered in the source file, and the same extended character expressed in the source file as a universal-character-name (i.e. using the \uXXXX notation), are handled equivalently.)

For gcc, you can change it using the option -finput-charset=charset. Additionally, you can change the execution character used to represet values at runtime. The proper option for this is-fexec-charset=charset for char (it defaults to utf-8) and-fwide-exec-charset=charset (which defaults to eitherutf-16 orutf-32 depending on the size of wchar_t).



The C++ standard doesn't say anything about source-code file encoding, so far as I know.

The usual encoding is (or used to be) 7-bit ASCII -- some compilers (Borland's, for instance) would balk at ASCII characters that used the high-bit. There's no technical reason that Unicode characters can't be used, if your compiler and editor accept them -- most modern Linux-based tools, and many of the better Windows-based editors, handle UTF-8 encoding with no problem, though I'm not sure that Microsoft's compiler will.

EDIT: It looks like Microsoft's compilers will accept Unicode-encoded files, but will sometimes produce errors on 8-bit ASCII too:

warning C4819: The file contains a character that cannot be represented
in the current code page (932). Save the file in Unicode format to prevent
data loss.


warning C4819: The file contains a character that cannot be represented in the current code page (936). Save the file in Unicode format to prevent data loss

//z 2012-07-06 10:22:32 AM IS2120@CSDN.T113491669


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值