C/C++教程

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

这篇关于Cannot use non-english characters correctly in your source code, which triggers elusive bugs when ca的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!