Conversions between ANSI, Unicode, and wide characters
Method One, use MultiByteToWideChar to convert ANSI characters to Unicode characters, and use WideCharToMultiByte to convert Unicode characters to ANSI characters.
Method Two, use "_t" to convert ANSI to a "generic" type string, convert ANSI to Unicode using "L", and use S to convert an ANSI string to a string* object in a managed C + + environment. For example:
TCHAR tstr[] = _t ("This is a Test"); wchar_t wszstr[] = L "This is a test"; string* str = S "This is a test";
Method Three, using the conversion macros and classes of ATL 7.0. ATL7.0 has refined and added a number of string conversion macros based on the original 3.0 and provided the corresponding classes, which have the uniform form shown in Figure 3:
Where the first C represents "class" for the purpose of distinguishing between ATL 3.0 macros, the second C represents a constant, and 2 is "to", and the ex indicates a buffer of a certain size. SourceType and destinationtype can be a, T, W, and OLE, meaning ANSI, Unicode, general type, and OLE strings, respectively. For example, CA2CT is a string constant that converts ANSI to a generic type. Here are some sample code:
LPTSTR tstr= ca2tex<16> ("This is a Test"); LPCTSTR tcstr= ca2ct ("This is a Test"); wchar_t wszstr[] = L "This is a test"; char* chstr = cw2a (WSZSTR);
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.