编译错误如下
Myapp.cpp
d:\vcpro\新建文件夹 (2)\my001\myapp.cpp(31) : fatal error C1010: unexpected end of file while looking for precompiled header directive
Error executing cl.exe.Myapp.obj - 1 error(s), 0 warning(s)
头文件如下:
//***********************************************
// MyApp.h
//class CMyApp:public CWinApp //见下②
{
public:
virtual BOOL InitInstance();
};class CMyFrame:public CFrameWnd
{
public:
CMyFrame();
protected:
afx_msg void OnLButtonDown(UINT nFlags,CPoint point);
afx_msg void OnPaint();
DECLARE_MESSAGE_MAP()
};
CPP文件如下
#include "afxwin.h"
#include "myapp.h"
CMyApp theApp;BOOL CMyApp::InitInstance ()
{
m_pMainWnd=new CMyFrame();
m_pMainWnd->ShowWindow (m_nCmdShow);
m_pMainWnd->UpdateWindow ();
return TRUE;
}BEGIN_MESSAGE_MAP(CMyFrame,CFrameWnd)
ON_WM_LBUTTONDOWN()
ON_WM_PAINT()
END_MESSAGE_MAP()CMyFrame::CMyFrame(){
Create(NULL,"MYAPP Application");
}
void CMyFrame::OnLButtonDown (UINT nFlags,CPoint point)
{
TRACE("Entering CMyFrame::OnLButtonDown - %lx,%d,%d\n",
(long)nFlags,point.x ,point.y);
}
void CMyFrame::OnPaint ()
{
CPaintDC dc(this);
dc.TextOut(0,0,"Hello World!");
}
Myapp.cpp
d:\vcpro\新建文件夹 (2)\my001\myapp.cpp(31) : fatal error C1010: unexpected end of file while looking for precompiled header directive
Error executing cl.exe.Myapp.obj - 1 error(s), 0 warning(s)
头文件如下:
//***********************************************
// MyApp.h
//class CMyApp:public CWinApp //见下②
{
public:
virtual BOOL InitInstance();
};class CMyFrame:public CFrameWnd
{
public:
CMyFrame();
protected:
afx_msg void OnLButtonDown(UINT nFlags,CPoint point);
afx_msg void OnPaint();
DECLARE_MESSAGE_MAP()
};
CPP文件如下
#include "afxwin.h"
#include "myapp.h"
CMyApp theApp;BOOL CMyApp::InitInstance ()
{
m_pMainWnd=new CMyFrame();
m_pMainWnd->ShowWindow (m_nCmdShow);
m_pMainWnd->UpdateWindow ();
return TRUE;
}BEGIN_MESSAGE_MAP(CMyFrame,CFrameWnd)
ON_WM_LBUTTONDOWN()
ON_WM_PAINT()
END_MESSAGE_MAP()CMyFrame::CMyFrame(){
Create(NULL,"MYAPP Application");
}
void CMyFrame::OnLButtonDown (UINT nFlags,CPoint point)
{
TRACE("Entering CMyFrame::OnLButtonDown - %lx,%d,%d\n",
(long)nFlags,point.x ,point.y);
}
void CMyFrame::OnPaint ()
{
CPaintDC dc(this);
dc.TextOut(0,0,"Hello World!");
}
并且要放在最上面,
要么你少了一个 }
2。你可能在if else中丢失{ }匹配符或if _debug endif之类的匹配丢失
编译过去了,可运行出现了以下错误:
debug Assertion failed!
program:d:\vcpro\my001\debug\my001.exe
file:appcore.cpp
line:85
for information on how your program can cause
an assertion failure,see the Visual C++ documentaion on asserts.
(press retry to debug the application)
BOOL CMyApp::InitInstance ()
{
m_pMainWnd=new CMyFrame();
m_pMainWnd->ShowWindow (m_nCmdShow);
m_pMainWnd->UpdateWindow ();
return TRUE;
}
至少应该LoadFrame吧