文档详情

ASCII_UNICODE_UTF8字符串互相转换的C++代码(国外英文资料).doc

发布:2017-06-09约字共43页下载文档
文本预览下载声明
ASCII_UNICODE_UTF8字符串互相转换的C++代码(国外英文资料) This is a class I wrote for the conversion between a variety of String, there are some used by. Net support in. Net String String ^ and transformation between the standard c + + String functions. Please forgive me for putting it in a namespace like dbsoft for reuse. Heres a simple example of using it: # include iostream # include string # include locale Using namespace STD. Include dbsoft/generic/string_shim. HPP Using the namespace dbsoft; Define PRINT (OSTREAM, exp) OSTREAM Int main () { Const char * pAsciiStr = address: /_%e2d_%b2%b2%c2%d2. Const wchar_t * pUnicodeStr = L address: /_%e2d_%b2%c2%d2. Cout / / make sure that you can print Chinese correctly on the simplified Chinese operating system, so you need to set localization ( CHS ); Wcout L UNICODE: pUnicodeStr endl; Cout -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- line -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- \ n; / / convert UNICODE to ASCII PRINT (cout, DBSOFT_CAST_TO_CHAR_STR (pUnicodeStr)) / / convert ASCII to UNICODE PRINT (wcout, DBSOFT_CAST_TO_WCHAR_STR (pAsciiStr)); / / convert ASCII to UTF8 STD: : basic_string dbsoft: : utf8_char strUtf8 = dbsoft: : string_shim dbsoft: : utf8_char (pAsciiStr).tostlstr () / / convert UTF8 to ASCII PRINT (cout, dbsoft: : string_shim char (strutf8.c_str ()). / / convert UTF8 to UNICODE PRINT (wcout, dbsoft: : string_shim wchar_t ().tostr ()); Return 0; } There are two main patterns of use, one is the direct use of predefined macro, I a second is the use of the explicit template class to transform, in fact is the same, the benefits of the macro is more obvious. In addition, the UTF8 convention is unsigned char. For UTF8, I used this class to handle the U
显示全部
相似文档