有一段程序,老是提示下面的错误,请大侠指点
MFC.CPP
f:\vc6\hmfc\mfc.cpp(8) : fatal error C1010: 
unexpected end of file while looking for precompiled header directive
MY.CPP
f:\vc6\hmfc\my.cpp(9) : fatal error C1010: 
unexpected end of file while looking for precompiled header directive
////////////////////////////////////////////
// MFC.cpp 
#include "my.h"extern CMyWinApp theApp;
CWinApp* AfxGetApp()

return theApp.m_pCurrentWinApp ; 
}/////////////////////////////////////////////
// MFC.h
#include<iostream.h>
class CWinApp
{
public:
CWinApp* m_pCurrentWinApp;
CWinApp::CWinApp()
{ cout << "CWinApp Constructor\n";}
CWinApp::~CWinApp()
{ cout << "CWinApp Destructor\n";}
};//global function
CWinApp* AfxGetApp();
////////////////////////////////////////////////
// My.Cpp
#include "My.h"
#include<iostream.h>
CMyWinApp theApp;void main()
{
CWinApp* pApp = AfxGetApp();
}///////////////////////////////////////////////////
// My.h
#include "mfc.h"class CMyWinApp:public CWinApp
{
public:
CMyWinApp::CMyWinApp(){ cout << "CMyWinApp Constructor\n";}
CMyWinApp::~CMyWinApp(){ cout << "CMyWinApp Destructor\n";}
}

解决方案 »

  1.   

    在MFC.cpp,My.cpp头部加上#include "stdafx.h"
      

  2.   

    在MFC.cpp和My.Cpp中添加
     #include "stdafx.h"
      

  3.   

    如果你的Project要用MFC,那么你加入Project中的所有.cpp文件都要包含
    stdafx.h 头文件, 否则就会出现你的那个错误
      

  4.   

    在my.h的最后一个}后少一个分号
      

  5.   

    在MFC.cpp,My.cpp头部加上#include "stdafx.h" 及在MY.H加了分号也出错:MFC.CPP
    f:\vc6\hmfc\mfc.cpp(2) :
    fatal error C1083: Cannot open precompiled header file: 'Debug/Hmfc.pch': No such file or directory
    MY.CPP
    f:\vc6\hmfc\my.cpp(9) : 
    fatal error C1010: unexpected end of file while looking for Hmfc.exe - 3 error(s), 1 warning(s)
      

  6.   

    你用的如果是mfc必须在.cpp文件包含afxstd头文件,不过你的程序好像不是mfc,是控制台编程模式的话,就生成一个空文件!在加入你的文件,试试!
      

  7.   

    在.cpp文件包含windows.h头文件,试试.
      

  8.   

    使用了MFC,必须要有#include "stdafx.h"头文件