ERROR :unexpected end of file while looking for precompiled header directive

Posted on 2001-08-03
Last Modified: 2013-11-20
I have added new files into My mfc single doc/view project.The listing is as follows

///////////// Myclass.h //////////////////////
#if !defined(AFX_MYCLASS_H__INCLUDED_)

#if _MSC_VER >= 1000
#pragma once
#endif // _MSC_VER >= 1000

class CMyclass : public CObject
     CString m_str;
     void PrintMsg();

#endif // !defined(AFX_MYCLASS_H__INCLUDED_)
/////////////////////// end ///////////////////////

///////////////////////// Myclass.cpp /////////////
#include "Myclass.h"


void CMyclass::PrintMsg()
     AfxMessageBox("Hello samuel");

/////////////////////// end //////////////////////

when i build this project i got the Error:"fatal error C1010: unexpected end of file while looking for precompiled header directive" How to slove it?
Question by:gymsam
  • 2
LVL 12

Accepted Solution

migel earned 50 total points
ID: 6348209
you haveto include header file, used for creation of precompilated header, i the each project file being compiled.
Usually MSVC vizards create stdaf.h file and use it to create precompilated header.
To resolve your problem just rewrite your cpp file:
#include "stdafx.h" //<<!!!
#include "Myclass.h"
void CMyclass::PrintMsg()
    AfxMessageBox("Hello samuel");
/////////////////////// end //////////////////////

Expert Comment

ID: 6348888
In some cases you do just need to add #include "stdafx.h" to the .cpp file.  This tells the compiler it is using precompiled headers.  However, there are situations in which you do not wish to use precompile headers.  In this case you need to go to the project settings, find the particular file in the tree on the left, click on the c\c++ tab and select precompiled headers from the combo.  Turn off precompiled headers for the particular file.  Since your are using MFC, in this case you need the first way.

Author Comment

ID: 6350909
Thank, i will check your suggestion and get back to you soon.

Author Comment

ID: 6358036
Thank you migel.Your suggestion is working fine.

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
xyBalance chalenge 58 88
sum67 challenge 35 93
twoTwo  challenge 35 96
mapBully challenge 6 115
Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

25 Experts available now in Live!

Get 1:1 Help Now