系统相关
首页 > 系统相关> > Cannot use non-english characters correctly in your source code, which triggers elusive bugs when ca

Cannot use non-english characters correctly in your source code, which triggers elusive bugs when ca

作者:互联网

This problem can cause the following elusive bugs by AUTOMATIC ENCODING CONVERSION without any warnings or errors:

  1. Cannot read or write strings of the type WCHAR , LPCWSTR... correctly; can not declare any non-English wchar_t with the format of L"おかしい" correctly. e.g: L"正£" cannot be correctly received by the windows API. You cannot easily notice that since you check the memory\the variables, those wchar_t variables are correctly encoded into UTF-16LE. But those variables cannot be correctly passed between services. If you only use those WChar[] in your program without calling any APIs, everything will be ok.
  2. Cannot use the CString correctly. CString st = _T("正£"); will actually create L"正£"
  3. Cannot use Windows API correctly: the API can receive and use those arguments without any warnings, yet non-ASCII bytes will be combined together to trigger unexpected behavior.
  4. In SAPI5, you can speak English text but cannot speak non-English text correctly. Strange symbols like öüäü€$ will be spoken.

Solution:
Change the encoding of the source files(e.g: Source.cpp) into UTF-16LE WITH BOM

标签:use,code,elusive,non,will,cannot,correctly,those
来源: https://www.cnblogs.com/xuesu/p/16663923.html