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

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_)
#define AFX_MYCLASS_H__INCLUDED_

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

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

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



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


CMyclass::CMyclass()
{


}
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?
gymsamAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
migelConnect With a Mentor Commented:
Hi!
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"
CMyclass::CMyclass()
{
}
void CMyclass::PrintMsg()
{
    AfxMessageBox("Hello samuel");
}
/////////////////////// end //////////////////////
0
 
LockiasCommented:
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.
0
 
gymsamAuthor Commented:
Thank, i will check your suggestion and get back to you soon.
0
 
gymsamAuthor Commented:
Thank you migel.Your suggestion is working fine.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.