请教高手:
  正在学习MFC,抄了一个简单的压键盘程序如下:红色部分是俺添加的,其他都是VC自己生成的,在编译时,出现如下一个错误,找不到文件 'Debug/Ch5Demo1.pch',原因可能是在哪里?Compiling...
Ch5Demo1View.cpp
c:\program files\microsoft visual studio\myprojects\ch5demo1\ch5demo1view.cpp(4) : fatal error C1083: Cannot open precompiled header file: 'Debug/Ch5Demo1.pch': No such file or directory
Error executing cl.exe.
// Ch5Demo1View.cpp : implementation of the CCh5Demo1View class
//#include "stdafx.h"
#include "Ch5Demo1.h"#include "Ch5Demo1Doc.h"
#include "Ch5Demo1View.h"#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif/////////////////////////////////////////////////////////////////////////////
// CCh5Demo1ViewIMPLEMENT_DYNCREATE(CCh5Demo1View, CView)BEGIN_MESSAGE_MAP(CCh5Demo1View, CView)
//{{AFX_MSG_MAP(CCh5Demo1View)
ON_WM_KEYDOWN()
//}}AFX_MSG_MAP
// Standard printing commands
ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
END_MESSAGE_MAP()/////////////////////////////////////////////////////////////////////////////
// CCh5Demo1View construction/destructionCCh5Demo1View::CCh5Demo1View()
{
// TODO: add construction code here}CCh5Demo1View::~CCh5Demo1View()
{
}BOOL CCh5Demo1View::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
//  the CREATESTRUCT cs return CView::PreCreateWindow(cs);
}/////////////////////////////////////////////////////////////////////////////
// CCh5Demo1View drawingvoid CCh5Demo1View::OnDraw(CDC* pDC)
{
CCh5Demo1Doc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
}/////////////////////////////////////////////////////////////////////////////
// CCh5Demo1View printingBOOL CCh5Demo1View::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}void CCh5Demo1View::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}void CCh5Demo1View::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}/////////////////////////////////////////////////////////////////////////////
// CCh5Demo1View diagnostics#ifdef _DEBUG
void CCh5Demo1View::AssertValid() const
{
CView::AssertValid();
}void CCh5Demo1View::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}CCh5Demo1Doc* CCh5Demo1View::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CCh5Demo1Doc)));
return (CCh5Demo1Doc*)m_pDocument;
}
#endif //_DEBUG/////////////////////////////////////////////////////////////////////////////
// CCh5Demo1View message handlersvoid CCh5Demo1View::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags) 
{
// TODO: Add your message handler code here and/or call default
AfxMessageBox("用户按下了键!") ;  //弹出提示对话框 CView::OnKeyDown(nChar, nRepCnt, nFlags);
}

解决方案 »

  1.   

    你不加这句话就能编译通过么?
    把工程目录下的pch、obj、debug文件夹都删掉然后重新编译下
      

  2.   

    谢谢答复! 我把新加的这句注解后,编译还是那个问题。偶一气之下,直接building,然后运行,居然ok,NND,不知是那里的问题。这是肿末会事情呀,糊涂?
      

  3.   

    一般这种情况很常见,选中工程,右键-》【清理】-》【重新生成】  可以在工程目录下看到.pch文件