About Main () and _tmain ()

Source: Internet
Author: User

1. What they have in common

    int _tmain (int argc, _tchar* argv[]) and int main (int argc, char* argv[]) , both are the main functions of the program, both of which are the entrance to the program.

2. Differences between the two

  Main () is the standard C + + function entry, the default character encoding format ANSI
The function name is:
int main ();
int main (int argc, char* argv[]);

  _tmain () is a program entry point function that is provided for automatic conversion of the Unicode character set and the ANSI character set.
The function name is:
int _tmain (int argc, TCHAR *argv[]), when your program's current character set is Unicode, int _tmain (int argc, TCHAR *argv[]) is translated into int wmain (int argc, WCHA r_t *argv[]); When your program's current character set is ANSI, int _tmain (int argc, TCHAR *argv[]) is translated into int main (int argc, char *argv[])

  _tmain This symbol is more common in VC + + created console project, this is to ensure that the migration of Unicode (General _t, _t, t () these things are related to Unicode), for the use of non-Unicode character set of the project, The actual main is no different (in fact, the use of the Unicode character set is not necessarily how much difference).

In addition , the definition of _tmain can be found in <tchar.h>, such as # define _tmain Main, so include # include <tchar.h>, and usually # include < Tchar.h> in # include "stdafx.h", so if you use int _tmain (int argc, TCHAR *argv[]) main function in the program, the header file will usually contain #include "stdafx.h" .

  As for the character encoding format ANSI and Unicode have and differ from the following article:

About Main () and _tmain ()

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.