乡下人产国偷v产偷v自拍,国产午夜片在线观看,婷婷成人亚洲综合国产麻豆,久久综合给合久久狠狠狠9

  • <output id="e9wm2"></output>
    <s id="e9wm2"><nobr id="e9wm2"><ins id="e9wm2"></ins></nobr></s>

    • 分享

      為什么會(huì)出現(xiàn)_tmain與stdafx.h

       埃德溫會(huì)館 2013-01-27

      為什么會(huì)出現(xiàn)_tmain與stdafx.h

      488人閱讀 評論(1) 收藏 舉報(bào)

      在visual c++ 2008 中,當(dāng)選擇編輯一個(gè)32位Win32控制臺應(yīng)用程序時(shí).初始狀態(tài)下系統(tǒng)自帶函數(shù):

      int _tmain(int argc, _TCHAR* argv[])

      {

      return 0;

      }

      上述Win32控制臺應(yīng)用程序的入口程序是用來存放機(jī)器的一個(gè)環(huán)境變量的,如:機(jī)器名,系統(tǒng)信息等.  

      其中:

      int argc               //參數(shù)個(gè)數(shù)

      char *argv[]          //字符串?dāng)?shù)組,字符串?dāng)?shù)組的每個(gè)單元是char*類型的,指向一個(gè)c風(fēng)格字符串。

                                   //_TCHAR類型是寬字符型字符串,和我們一般常用的字符串不同,它是32位或者更高的操作系統(tǒng)中所使用的類型.

      出處:

      #include   <iostream>  

      #include   <string.h>  

      using   namespace   std;  

      void main(int argc,char*argv[],char*envp[])  

      {  

      int   iNumberLines=0;         //   Default   is   no   line   numbers.  

                                                 //   If   more   than   .EXE   filename   supplied,   and   if   the    

                                                 //   /n   command-line   option   is   specified,   the   listing  

                                                  //   of   environment   variables   is   line-numbered.

           if(argc==2&&stricmp(argv[1],"/n")==0)  

                 {

                      iNumberLines=1;

                  }                               //   Walk   through   list   of   strings   until   a   NULL   is   encountered.  

           for(int i=0;envp[i]!=NULL;++i )  

               {       

                      if(!iNumberLines)  

                        cout<<i<<":"<<envp[i]<<"/n";  

                }  

      }

      The envp parameter is a pointer to an array of null-terminated strings that represent the values set in the user’s environment variables   ------這是MSDN的原話.

       

      _tmain:

      1.    Main是所有c或c++的程序執(zhí)行的起點(diǎn),_tmain是main為了支持unicode所使用的main的別名 ._tmain()不過是unicode版本的的main() .

      2.    _tmain需要一個(gè)返回值,而main默認(rèn)為void.

      3.    _tmain的定義在<tchar.h>可以找到,如#define _tmain main,所以要加

      #include <tchar.h>才能用。_tmain()是個(gè)宏,如果是UNICODE則他是wmain()否則他是main().

      4.    (一般_t、_T、T()這些東西都是宏都和unicode有關(guān)系),對于使用非unicode字符集的工程來說,實(shí)際上和main沒有差別(其實(shí)就算是使用unicode字符集也未必有多大的差別)。

      5.    因此_tmain compile后仍為main,所以都可以執(zhí)行.

      main()是WINDOWS的控制臺程序(32BIT)或DOS程序(16BIT).

      WinMain()是WINDOWS的GUI程序.

      另外,wmain也是main的另一個(gè)別名,是為了支持二個(gè)字節(jié)的語言環(huán)境

      -----------------------

      int main( int argc[ , char *argv[ ] [, char *envp[ ] ] ] );

      wmain( int argc, wchar_t *argv[ ], wchar_t *envp[ ] )

      int _tmain(int argc, _TCHAR* argv[])

      出處:

               You can also use _tmain, which is defined in TCHAR.h. _tmain will resolve to main unless _UNICODE is defined, in which case _tmain will resolve to wmain.---------------------------------------------MSDN原話

      http://hi.baidu.com/bytelin/blog/item/df37ccef33e30f3fadafd5ea.html

      用過C的人都知道每一個(gè)C的程序都會(huì)有一個(gè)main(),但有時(shí)看別人寫的程序發(fā)現(xiàn)主函數(shù)不是int main(),而是int _tmain(),而且頭文件也不是<iostream.h>而是<stdafx.h>,會(huì)困惑吧?

      一起來看看他們有什么關(guān)系吧

        首先,這個(gè)_tmain()是為了支持unicode所使用的main一個(gè)別名而已,既然是別名,應(yīng)該有宏定義過的,在哪里定義的呢?就在那個(gè)讓你困惑的<stdafx.h>里,有這么兩行

      #include <stdio.h>
      #include <tchar.h>

      我們可以在頭文件<tchar.h>里找到_tmain的宏定義     

      #define _tmain      main

      所以,經(jīng)過預(yù)編譯以后, _tmain就變成main了,這下明白了吧


      btw,<stdafx.h>是用來預(yù)編譯用的頭文件,旨在減小文件的大小和減少編譯的時(shí)間,想進(jìn)一步了解,請看百科

      http://baike.baidu.com/view/1344257.html?wtp=tt

        本站是提供個(gè)人知識管理的網(wǎng)絡(luò)存儲空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn)。請注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點(diǎn)擊一鍵舉報(bào)。
        轉(zhuǎn)藏 分享 獻(xiàn)花(0

        0條評論

        發(fā)表

        請遵守用戶 評論公約

        類似文章 更多