Character encoding Problems
C/C ++ has a long development process. Early characters are in the form of multibyte, and Unicode is added to the later stage to process multiple languages, therefore, Unicode supports the built-in characters later than Java and C.
I18n internationalization: Short for internationalization
L10nLocalization: Short for localization
MS-help: // Ms. VSCC. v90/ms. msdnqtr. v90.chs/dv_vccrt/html/ee536a04-3558-4729-8e10-6dabcde055fd.htm Internationalization
MS-help: // Ms. VSCC. v90/ms. msdnqtr. v90.chs/dv_vccrt/html/4e573c05-8800-468b-ae5f-76ff7409835e.htm Data Type Mappings
MS-help: // Ms. VSCC. v90/ms. msdnqtr. v90.chs/dv_vccrt/html/a03de0db-8118-4bd9-a03f-640e8dfc5ed3.htm a sample generic-text Program
Character Initialization
|
Genreic
[This is related to the compilation type. Unicode is Unicode during compilation] |
_ Tchar buff [_ max_path] = {text ("hello ")}; Tchar * S1 = _ T ("tchar with compile option "); Tchar * S2 = _ text ("tchar "); |
|
Unicode |
Wchar_t * wmsg = l "is "; Wchar * UC = l "is UC "; |
|
MBCS |
Char * amsg = "Reversed "; |
Character conversion
|
Windows |
Widechartomultibyte
Multibytetowidechar
Of course, mfc atl and related libraries have related conversion auxiliary functions.Source code.
(For example, c: \ Program Files \ Microsoft Visual Studio 10.0 \ Vc \ atlmfc \ include \ atlcomcli. h)
Medium a2wbstr) |
|
Iconv |
GNU open-source component for conversion of multiple character codes
Cross-platform |
Example
/*Construct a function using ccombstr (_ in_opt_z _ lpcstr psrc)
Request space sysallocstringlen
Put the multibytetowidechar character transcoding in the dynamic space m_str Member
Improvement Method: Unicode assignment is used directly. Therefore, you must be familiar with the auxiliary character processing functions and macros such as tchar wchar _ t Text L.
TEXT = l "Demo ";*/Ccombstr text ="Demo";The following is from an actual softwareCodeError usage
# Include <String>Using NamespaceSTD;VoidDemo (BSTR bstrlibname) {_ bstr_t bstr_name (bstrlibname );StringStrname; strname = bstr_name; strname = strname. substr (1 );// Response //¡.Cstring next (strname. c_str ());// Process failed ¡// Configure //¡}
Analysis
The above code is introduced by different people for maintenance. It is estimated that different people are familiar with and use different libraries. For example, a is familiar with STL, B is familiar with MFC ,..., However, such code is integrated,
If efficiency is required, the above Code has great potential efficiency risks.
As long as you locate the codes of stl mfc and other classes in Vs, you can know that such objects apply for and assign values to more than N spaces during use.
Possible Improvement Methods
If the above input is BSTR, it is generally better to use this type for processing without introducing unnecessary object conversions.
Some people may want to use functions provided by existing objects to reduce unnecessary encoding. At this time, it is best to introduce only one class, STL, or cstring.
(In this case, we recommend that you select a class that matches BSTR, such as wstring, to reduce the conversion problem)
To be more common in projects, you can also package a class for special project processing to reduce conversion and space application problems.