如题所述
#include "stdafx.h"
æ¯é¢ç¼è¯å¤çå¨æstdafx.hæ件ä¸çå 容å è½½å°ç¨åºä¸æ¥ã
stdafx.h
1å称çè±æå ¨ç§°ä¸ºï¼Standard Application Fram Extend
æè°å¤´æ件é¢ç¼è¯ï¼å°±æ¯æä¸ä¸ªå·¥ç¨(Project)ä¸ä½¿ç¨çä¸äºMFCæ å头æ件(å¦Windows.HãAfxwin.H)é¢å ç¼è¯ï¼ä»¥å该工ç¨ç¼è¯æ¶ï¼ä¸åç¼è¯è¿é¨å头æ件ï¼ä» ä» ä½¿ç¨é¢ç¼è¯çç»æãè¿æ ·å¯ä»¥å å¿«ç¼è¯é度ï¼èçæ¶é´ã
é¢ç¼è¯å¤´æ件éè¿ç¼è¯stdafx.cppçæï¼ä»¥å·¥ç¨åå½åï¼ç±äºé¢ç¼è¯ç头æ件çåç¼æ¯âpchâï¼æ以ç¼è¯ç»ææ件æ¯projectname.pchã
ç¼è¯å¨éè¿ä¸ä¸ªå¤´æ件stdafx.hæ¥ä½¿ç¨é¢ç¼è¯å¤´æ件ãstdafx.hè¿ä¸ªå¤´æ件åæ¯å¯ä»¥å¨projectçç¼è¯è®¾ç½®éæå®çãç¼è¯å¨è®¤ä¸ºï¼ææå¨
æ令#include "stdafx.h"åç代ç é½æ¯é¢ç¼è¯çï¼å®è·³è¿#include "stdafx.
h"æ令ï¼ä½¿ç¨projectname.pchç¼è¯è¿æ¡æ令ä¹åçææ代ç ã
å æ¤ï¼ææçMFCå®ç°æ件第ä¸æ¡è¯å¥é½æ¯ï¼#include "stdafx.h"ã
2 详ç»å·¥ä½åçåä½ç¨
stdafx.hä¸æ²¡æå½æ°åºï¼åªæ¯å®ä¹äºä¸äºç¯å¢åæ°ï¼ä½¿å¾ç¼è¯åºæ¥çç¨åºè½å¨32ä½çæä½ç³»ç»ç¯å¢ä¸è¿è¡ã
WindowsåMFCçincludeæ件é½é常大ï¼å³ä½¿æä¸ä¸ªå¿«éçå¤çç¨åºï¼ç¼è¯ç¨åºä¹è¦è±è´¹ç¸å½é¿çæ¶é´æ¥å®æå·¥ä½ãç±äºæ¯ä¸ª.CPPæ件é½å å«ç¸åçincludeæ件ï¼ä¸ºæ¯ä¸ª.CPPæ件é½éå¤å¤çè¿äºæ件就æ¾å¾å¾å»äºã
为é¿å è¿ç§æµªè´¹ï¼AppWizardåVisualC++ç¼è¯ç¨åºä¸èµ·è¿è¡å·¥ä½ï¼å¦ä¸æ示ï¼
âAppWizard建ç«äºæ件stdafx.hï¼è¯¥æ件å å«äºææå½åå·¥ç¨æ件éè¦çMFCincludeæ件ãä¸è¿ä¸æ件å¯ä»¥é被éæ©çé项èååã
âAppWizardç¶å就建ç«stdafx.cppãè¿ä¸ªæ件é常é½æ¯ä¸æ ·çã
âç¶åAppWizard就建ç«èµ·å·¥ç¨æ件ï¼è¿æ ·ç¬¬ä¸ä¸ªè¢«ç¼è¯çæ件就æ¯stdafx.cppã
âå½VisualC++ç¼è¯stdafx.cppæ件æ¶ï¼å®å°ç»æä¿åå¨ä¸ä¸ªå为stdafx.pchçæ件éã(æ©å±åpch表示é¢ç¼è¯å¤´æ件ã)
âå½VisualC++ç¼è¯éåçæ¯ä¸ª.cppæ件æ¶ï¼å®é 读并使ç¨å®åçæç.pchæ件ãVisualC++ä¸ååæWindowsincludeæ件ï¼é¤éä½ åç¼è¾äºstdafx.cppæstdafx.hã
è¿ä¸ªææ¯å¾ç²¾å·§ï¼ä½ ä¸è¿ä¹è®¤ä¸ºåï¼(è¿è¦è¯´ä¸å¥ï¼Microsoft并éæ¯é¦å éç¨è¿ç§ææ¯çå ¬å¸ï¼Borlandææ¯ã)å¨è¿ä¸ªè¿ç¨ä¸ä½ å¿ é¡»éµå®ä»¥ä¸è§åï¼
âä½ ç¼åçä»»ä½.cppæ件é½å¿ é¡»é¦å å å«stdafx.hã
âå¦æä½ æå·¥ç¨æ件éç大å¤æ°.cppæ件éè¦.hæ件ï¼é¡ºä¾¿å°å®ä»¬å å¨stdafx.h(åé¨)ä¸ï¼ç¶åé¢ç¼è¯stdafx.cppã
âç±äº.pchæä»¶å ·æ大éç符å·ä¿¡æ¯ï¼å®æ¯ä½ çå·¥ç¨æ件éæ大çæ件ã
å¦æä½ çç£ç空é´æéï¼ä½ å°±å¸æè½å°è¿ä¸ªä½ ä»æ²¡ä½¿ç¨è¿çå·¥ç¨æ件ä¸ç.pchæ件å é¤ãæ§è¡ç¨åºæ¶å¹¶ä¸éè¦å®ä»¬ï¼ä¸éçå·¥ç¨æ件çéæ°å»ºç«ï¼å®ä»¬ä¹èªå¨å°éæ°å»ºç«ã
3 å¦ä½çè§£å ¶åç
éä¿ä¸ç¹è¯´
å½æ们使ç¨AppWizardæ¥èªå¨çææäºé¡¹ç®çæ¶å,ç³»ç»ä¼èªå¨ææéè¦includeç头æ件å¨stdafx.hä¸å includeä¸ä¸,è¿æ ·,æ
们åªéè¦ç´æ¥includeè¿ä¸ªstdafx.hæ件å³å¯.å 为åä¸ä¸ªé¡¹ç®ä¸çä¸åæºæ件CPPé½å å«ç¸åçincludeæ件,è¿æ ·,为æ¯ä¸ª.CPPæ
件é½éå¤includeè¿äºæ件就æ¾å¾å¾å»äºãå½ç¶å¦æä½ ä¸ç¨MFCçè¯å°±ä¸ç¨äºãå³ï¼å¨æ¯ä¸ª.cppæ件ä¸é½include stdafx.h
å°±ç¸å½äºå å«äºå ¶ä»çå¦iostream.hçæ件
4 ä¸stdio.hçåºå«
æ们ä¸è¬ç¨TCævcç¼è¯Cç¨åºçæ¶åé½è¦é¦å å å«è¿ä¸ªstdio.h头æ件ï¼è¿ä¸ªå¤´æ件éé¢å å«äºscanfåprintfå½æ°çå®ä¹ï¼å¦ææ们ä¸å¨ç¨
åºå¼å¤´includeè¿ä¸ªæ件ï¼é£ä¹ä½ è°ç¨ä¸é¢è¿ä¸¤ä¸ªå½æ°å°±ä¸ä¼æåï¼å®å ¶å®åc++ä¸çiostream.hæ件çä½ç¨å·®ä¸å¤çï¼å®ä»¬ä¸è¬é½å·²ç»å¨
stdafx.hæ件ä¸è¢«å å«ã
æ¯é¢ç¼è¯å¤çå¨æstdafx.hæ件ä¸çå 容å è½½å°ç¨åºä¸æ¥ã
stdafx.h
1å称çè±æå ¨ç§°ä¸ºï¼Standard Application Fram Extend
æè°å¤´æ件é¢ç¼è¯ï¼å°±æ¯æä¸ä¸ªå·¥ç¨(Project)ä¸ä½¿ç¨çä¸äºMFCæ å头æ件(å¦Windows.HãAfxwin.H)é¢å ç¼è¯ï¼ä»¥å该工ç¨ç¼è¯æ¶ï¼ä¸åç¼è¯è¿é¨å头æ件ï¼ä» ä» ä½¿ç¨é¢ç¼è¯çç»æãè¿æ ·å¯ä»¥å å¿«ç¼è¯é度ï¼èçæ¶é´ã
é¢ç¼è¯å¤´æ件éè¿ç¼è¯stdafx.cppçæï¼ä»¥å·¥ç¨åå½åï¼ç±äºé¢ç¼è¯ç头æ件çåç¼æ¯âpchâï¼æ以ç¼è¯ç»ææ件æ¯projectname.pchã
ç¼è¯å¨éè¿ä¸ä¸ªå¤´æ件stdafx.hæ¥ä½¿ç¨é¢ç¼è¯å¤´æ件ãstdafx.hè¿ä¸ªå¤´æ件åæ¯å¯ä»¥å¨projectçç¼è¯è®¾ç½®éæå®çãç¼è¯å¨è®¤ä¸ºï¼ææå¨
æ令#include "stdafx.h"åç代ç é½æ¯é¢ç¼è¯çï¼å®è·³è¿#include "stdafx.
h"æ令ï¼ä½¿ç¨projectname.pchç¼è¯è¿æ¡æ令ä¹åçææ代ç ã
å æ¤ï¼ææçMFCå®ç°æ件第ä¸æ¡è¯å¥é½æ¯ï¼#include "stdafx.h"ã
2 详ç»å·¥ä½åçåä½ç¨
stdafx.hä¸æ²¡æå½æ°åºï¼åªæ¯å®ä¹äºä¸äºç¯å¢åæ°ï¼ä½¿å¾ç¼è¯åºæ¥çç¨åºè½å¨32ä½çæä½ç³»ç»ç¯å¢ä¸è¿è¡ã
WindowsåMFCçincludeæ件é½é常大ï¼å³ä½¿æä¸ä¸ªå¿«éçå¤çç¨åºï¼ç¼è¯ç¨åºä¹è¦è±è´¹ç¸å½é¿çæ¶é´æ¥å®æå·¥ä½ãç±äºæ¯ä¸ª.CPPæ件é½å å«ç¸åçincludeæ件ï¼ä¸ºæ¯ä¸ª.CPPæ件é½éå¤å¤çè¿äºæ件就æ¾å¾å¾å»äºã
为é¿å è¿ç§æµªè´¹ï¼AppWizardåVisualC++ç¼è¯ç¨åºä¸èµ·è¿è¡å·¥ä½ï¼å¦ä¸æ示ï¼
âAppWizard建ç«äºæ件stdafx.hï¼è¯¥æ件å å«äºææå½åå·¥ç¨æ件éè¦çMFCincludeæ件ãä¸è¿ä¸æ件å¯ä»¥é被éæ©çé项èååã
âAppWizardç¶å就建ç«stdafx.cppãè¿ä¸ªæ件é常é½æ¯ä¸æ ·çã
âç¶åAppWizard就建ç«èµ·å·¥ç¨æ件ï¼è¿æ ·ç¬¬ä¸ä¸ªè¢«ç¼è¯çæ件就æ¯stdafx.cppã
âå½VisualC++ç¼è¯stdafx.cppæ件æ¶ï¼å®å°ç»æä¿åå¨ä¸ä¸ªå为stdafx.pchçæ件éã(æ©å±åpch表示é¢ç¼è¯å¤´æ件ã)
âå½VisualC++ç¼è¯éåçæ¯ä¸ª.cppæ件æ¶ï¼å®é 读并使ç¨å®åçæç.pchæ件ãVisualC++ä¸ååæWindowsincludeæ件ï¼é¤éä½ åç¼è¾äºstdafx.cppæstdafx.hã
è¿ä¸ªææ¯å¾ç²¾å·§ï¼ä½ ä¸è¿ä¹è®¤ä¸ºåï¼(è¿è¦è¯´ä¸å¥ï¼Microsoft并éæ¯é¦å éç¨è¿ç§ææ¯çå ¬å¸ï¼Borlandææ¯ã)å¨è¿ä¸ªè¿ç¨ä¸ä½ å¿ é¡»éµå®ä»¥ä¸è§åï¼
âä½ ç¼åçä»»ä½.cppæ件é½å¿ é¡»é¦å å å«stdafx.hã
âå¦æä½ æå·¥ç¨æ件éç大å¤æ°.cppæ件éè¦.hæ件ï¼é¡ºä¾¿å°å®ä»¬å å¨stdafx.h(åé¨)ä¸ï¼ç¶åé¢ç¼è¯stdafx.cppã
âç±äº.pchæä»¶å ·æ大éç符å·ä¿¡æ¯ï¼å®æ¯ä½ çå·¥ç¨æ件éæ大çæ件ã
å¦æä½ çç£ç空é´æéï¼ä½ å°±å¸æè½å°è¿ä¸ªä½ ä»æ²¡ä½¿ç¨è¿çå·¥ç¨æ件ä¸ç.pchæ件å é¤ãæ§è¡ç¨åºæ¶å¹¶ä¸éè¦å®ä»¬ï¼ä¸éçå·¥ç¨æ件çéæ°å»ºç«ï¼å®ä»¬ä¹èªå¨å°éæ°å»ºç«ã
3 å¦ä½çè§£å ¶åç
éä¿ä¸ç¹è¯´
å½æ们使ç¨AppWizardæ¥èªå¨çææäºé¡¹ç®çæ¶å,ç³»ç»ä¼èªå¨ææéè¦includeç头æ件å¨stdafx.hä¸å includeä¸ä¸,è¿æ ·,æ
们åªéè¦ç´æ¥includeè¿ä¸ªstdafx.hæ件å³å¯.å 为åä¸ä¸ªé¡¹ç®ä¸çä¸åæºæ件CPPé½å å«ç¸åçincludeæ件,è¿æ ·,为æ¯ä¸ª.CPPæ
件é½éå¤includeè¿äºæ件就æ¾å¾å¾å»äºãå½ç¶å¦æä½ ä¸ç¨MFCçè¯å°±ä¸ç¨äºãå³ï¼å¨æ¯ä¸ª.cppæ件ä¸é½include stdafx.h
å°±ç¸å½äºå å«äºå ¶ä»çå¦iostream.hçæ件
4 ä¸stdio.hçåºå«
æ们ä¸è¬ç¨TCævcç¼è¯Cç¨åºçæ¶åé½è¦é¦å å å«è¿ä¸ªstdio.h头æ件ï¼è¿ä¸ªå¤´æ件éé¢å å«äºscanfåprintfå½æ°çå®ä¹ï¼å¦ææ们ä¸å¨ç¨
åºå¼å¤´includeè¿ä¸ªæ件ï¼é£ä¹ä½ è°ç¨ä¸é¢è¿ä¸¤ä¸ªå½æ°å°±ä¸ä¼æåï¼å®å ¶å®åc++ä¸çiostream.hæ件çä½ç¨å·®ä¸å¤çï¼å®ä»¬ä¸è¬é½å·²ç»å¨
stdafx.hæ件ä¸è¢«å å«ã
温馨提示:答案为网友推荐,仅供参考