Explore VC _t (""), found that: double-byte character/multibyte character is stored in the small end (at least in the VC2013 environment)

Source: Internet
Author: User

Programmers who transition from VC6.0 to VS2013 should be confused about the way characters behave, often using _t ("") to display characters as they wish.

In fact _t ("") is a macro that acts as a compatible function that enables the compiler to compile strings in the default Character set form (ANSI or Unicode).


In VC2013 's Tchar.h file, I extracted some of the code, as follows:

This part of the code is very intuitive, when the Unicode character set is used, the compiler compiles the strings in _t ("") into Unicode form, and when the ANSI character set is used, the compiler compiles the strings in _t ("") into ANSI form.


Again, the character set.

Two character sets, Unicode and ANSI, are used under Windows. In the current Windows environment, the Unicode character set is stored in double-byte form, and ANSI is stored as a single byte (that is, 8-bit char).

As far as I know, the VC6.0 compiler uses the ANSI character set by default, and the Unicode character set is used by default when VS2010 or which version begins.

As for why there is a Unicode character set, mainly because the 8-bit ANSI character set can represent a maximum of 256 characters, only to meet the requirements of a very small number of areas, such as Britain and America, such as China, Chinese characters + symbols, a lot, 256 characters is far enough.


It is worth mentioning that characters in Unicode form are actually stored in small ends. Not much to say, see the code:

Operation Result:





VS2013 also does not support char16_t (C++11)! This code is compiled and run on http://cpp.sh/, which is very powerful and supports the new features of C + + very well.


Explore VC _t (""), found that: double-byte character/multibyte character is stored in the small end (at least in the VC2013 environment)

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.