Functions of string-related macros _ T, text, _ text, and l in VC

Source: Internet
Author: User

1. Add an L to the front of the string:
For example, l "my string" indicates converting an ANSI string to a unicode string, that is, each character occupies two bytes.
Strlen ("ASD") = 3;
Strlen (L "ASD") = 6;

2. The _ t macro can enclose a string enclosed by quotation marks. Based on your environment settings, the compiler selects an appropriate (UNICODE or ANSI) Character Processing Method Based on the compiling target environment.
If Unicode is defined, the _ t macro adds an L to the front of the string. In this case, _ T ("ABCD") is equivalent to L "ABCD", which is a wide string.
If not defined, the _ t Macro will not add the L before the string. _ T ("ABCD") is equivalent to "ABCD"

3. Text, _ text and _ t are the same

See the following three statements:
Tchar szstr1 [] = text ("str1 ");
Char szstr2 [] = "str2 ";
Wchar szstr3 [] = L ("str3 ");
The first sentence is interpreted as the third sentence when Unicode is defined. If no definition is made, it is the second sentence.
However, whether Unicode is defined or not, an ANSI string is generated, and the third sentence is always a unicode string.
We recommend that you use the first representation for program portability.
However, in some cases, a character must be ANSI or Unicode.

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.