Win32 console Unicode _ tmain _ tchar

Source: Internet
Author: User
Tags visual studio 2010

Refer:

Http://stackoverflow.com/questions/895827/what-is-the-difference-between-tmain-and-main-in-c

Http://msdn.microsoft.com/en-US/library/fzc2cy7w (V = vs.80). aspx

On the Win32 ConsoleProgramUnder development,

Visual c ++ extends the Standard C ++ main function, defines the wmain entry, and adds the wchar_t keyword to support Unicode (UTF-16) characters.

(Correspondingly, the original ASCII string functions have corresponding _ wxxx, _ TXXX series functions)

At the same time, _ tmain is defined for flexible conversion between wmain and Main,

The _ tchar is defined for flexible conversion between wchar_t and char.

When _ Unicode is defined, wmain and wchar_t are used; otherwise, main and Char are used.

In Visual Studio 2010, enable and disable _ Unicode as follows:

Enter project properties,

In the tree menu on the left, choose configuration properties-> General

Under project defaults on the right, the character set option is set to not set or Unicode.

In Unicode, an '\ 0' byte is added before ASCII,

In this way, in x86 systems, only the first ASCII character is output if Unicode characters are Output Using cout due to the use of small-end notation.

That is:

 
Wchar_t * WCHR = l "ABC"; cout <(char *) WCHR <Endl; wcout <WCHR <Endl;

Output:

 
AABC

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.