13
votes

So I have been trying to learn cpp and I was writing a program, and when I try to build the solution, it gives an error saying

unexpected end of file while looking for precompiled header. Did you forget to add #include "pch.h" to your source?

Then I included it and I got the same error, and also another saying

cannot open source file pch.h

screenshot

2
Is pch.h at the same directory as they file you included? You should provide an verifiable example: stackoverflow.com/help/mcve. Any way, my guess is that the compiler is not finding pch.h. Please provide the code, or the concerned parts of itgeckos
This is the behaviour of Visual Studio compiler. When you are using 'Precompiled Headers' mode, you need to add #include "pch.h" at the beginning of your file (as first include) or disable Precompiled Headers as you see in the answer of selbie.Julo

2 Answers

24
votes

One option, if you are new to c++, is to just turn off pre-compiled headers in the project settings.

0
votes

Your .cpp file is probably not in the same directory as pch.h