Windows style and C/C ++ style: Unicode vs _ Unicode and text () vs _ T ()

Source: Internet
Author: User
From: http://www.mouseos.com/win64/TEXT_T.html

For programming on Windows, strings are often used:

  1. Text ()Macro
  2. _ T ()Macro

These two macros are used to classify string constants. In the following code:

Lptstr lpstra =Text("Hello ");

Lptstr lpstrb =_ T("Hello ");

UseText ()And_ T ()The results are the same.

However, they represent two different programming styles:

  1. Windows programming style
  2. C/C ++ programming style

The typical meanings of these two styles are:

_ Tchar * Buf = _ T ("hello ");

Or

Lptstr lpbuf = text ("hello ");

Text ()Macro header files defined in WindowsWinnt. h,_ T ()Macro defines the header file of visual VC/C ++Tchar. hTherefore, text () represents the windows programming style, and _ T () represents the C/C ++ style.

InWinnt. hIn the header file, useUnicodeDefinition:

   1: #ifdef UNICODE

   2: ... ...

   3: #define __TEXT(quote) L##quote 

   4: /* for UNICODE */

   5: ... ...

   6: #else

   7: ... ...

   8: #define __TEXT(quote) quote 

   9: /* for ANSI */

  10: ... ...

  11: #endif

  12: #define TEXT(quote) __TEXT(quote)

Text ()Unicode characters are used when Unicode is defined. Otherwise, ANSI characters are used.

InTchar. hIn the header file, use_ UncodeDefinition:

   1: #ifdef _UNICODE

   2: ... ...

   3: #define __T(x) L##x 

   4: /* for UNICODE */

   5: ... ...

   6: #else

   7: ... ...

   8: #define __T(x) x 

   9: /* for ANSI */

  10: ... ...

  11: #endif

  12: #define _T(x) __T(x)

In programming, you should always maintain your programming style,SuggestionsYouDo not mixText () and _ T () macros, although the results are the same.

However, for programming on windows, I suggest you alwaysMaintain the windows programming styleTo maintain consistency with the system.

Therefore, we recommend that you useText ()Macro.

Related Article

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.