关于main()和_tmain()

1.两者的共同点

    int _tmain(int argc, _TCHAR* argv[])    和  int main(int argc, char* argv[])  ,两者都是程序的主函数,两者都是程序的入口。

2.两者的不同点

  main()是标准C++的函数入口,默认字符编码格式ANSI
  函数名为:
    int main();
    int main(int argc, char* argv[]);

  _tmain()是提供的对unicode字符集和ANSI字符集进行自动转换用的程序入口点函数。
  函数名为:
    int _tmain(int argc, TCHAR *argv[])  ,当你程序当前的字符集为unicode时,int _tmain(int argc, TCHAR *argv[])会被翻译成int wmain(int argc, wchar_t *argv[]) ;当你程序当前的字符集为ANSI时,int _tmain(int argc, TCHAR *argv[])会被翻译成int main(int argc, char *argv[])

  _tmain这个符号多见于VC++创建的控制台工程中,这个是为了保证移植unicode而加入的(一般_t、_T、T()这些东西都和unicode有关系),对于使用非unicode字符集的工程来说,实际main没有差别(其实就算是使用unicode字符集也未必有多大的差别)。

  另外, _tmain的定义在<tchar.h>可以找到,如#define _tmain main,所以要包含#include <tchar.h>,而通常#include <tchar.h>在#include "stdafx.h"会包含,所以程序中若是使用int _tmain(int argc, TCHAR *argv[])主函数,通常头文件会包含#include "stdafx.h"

  至于字符编码格式ANSI和unicode有和区别见下一篇文章:http://www.cnblogs.com/Steven-Love-Arlene/p/4783718.html

原文地址:https://www.cnblogs.com/xiaopanlyu/p/4783324.html