That seems a bit weird. If stdafx.h had an extra #endif you shouldnt be able to compile. In the file you are working in, check ALL the includes to make sure they have matching #ifdefs and #endifs Just because you are getting the error in this particular file, it does not mean that the actual culprit of the unmatching #endif exists in the writing verbatim what is in the include file in place of the #include statment. For Example
//********* FILE ex.h *************
#ifdef EX_H
#define EX_H
#include "abc.h"
#endif
#endif // notice the extra endif
//******* END OF EX.h ************
//******** OTHER FILE other.h *****
#ifdef OTHER
#define OTHER
#include "ex.h"
#endif
//***********************************
In this case the file other.h will give the error for an un matching endif (If i remember correctly). All I really remember is I have seen this before and the error didnt really exist in the file the compiler said it did. Also, you can compile to just the preprocessor and see what it looks like. I forget the code for this but it is in the VC++ documentation.
I didn't actually meant that there was an extra "#endif" at the end of the file "stdafx.h" but still it is difficult to explain why there is an error occuring when puting and "#endif" after those lines:
I have try it myself and there was the same problem.
The only way out of this is to not put any "#endif" after the two previous line of code.
VC++ treats stdafx.h in a weird way, depending on your project settings. Make sure your project is highlighted then hit Alt+F7 to bring up your project settings. In the C/C++ tab, use the combo box to go to "Precompiled Headers".
Basically, if you are using precompiled headers and "stdafx.h" is NOT included in a .cpp file, the .cpp file will produce lots of weird errors... most commonly, it won't find the end of the file.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.